Click here to Skip to main content
15,900,378 members
Home / Discussions / C#
   

C#

 
QuestionEquivalent way to achieve const or readonly return type from method Pin
bob1697227-Jan-11 5:09
bob1697227-Jan-11 5:09 
AnswerRe: Equivalent way to achieve const or readonly return type from method Pin
_Erik_27-Jan-11 5:33
_Erik_27-Jan-11 5:33 
AnswerRe: Equivalent way to achieve const or readonly return type from method Pin
Luc Pattyn27-Jan-11 5:36
sitebuilderLuc Pattyn27-Jan-11 5:36 
AnswerRe: Equivalent way to achieve const or readonly return type from method PinPopular
jschell27-Jan-11 8:45
jschell27-Jan-11 8:45 
GeneralRe: Equivalent way to achieve const or readonly return type from method Pin
fjdiewornncalwe27-Jan-11 8:49
professionalfjdiewornncalwe27-Jan-11 8:49 
GeneralRe: Equivalent way to achieve const or readonly return type from method Pin
bob1697227-Jan-11 8:56
bob1697227-Jan-11 8:56 
AnswerRe: Equivalent way to achieve const or readonly return type from method Pin
RobCroll27-Jan-11 12:06
RobCroll27-Jan-11 12:06 
GeneralRe: Equivalent way to achieve const or readonly return type from method Pin
bob1697227-Jan-11 18:35
bob1697227-Jan-11 18:35 
I'm just trying to let other classes have access to the data in the object so cloning would cost too much. The process will need to access the data enough that I only want to pass references around for efficiency.

Creating a read-only version would only be possible if all the data were available to the constructor but unfortunately the process requires a few stages to fully initialize the objects so a few properties need to be accessible by other classes. Since "friend" doesn't exist in C# and since making it "internal" and placing those classes in a different assembly seems like overkill, I'm just going to create an interface to implement that only provides accessors and pass a reference of that interface around to make the const intention apparent in the code.

Someone had suggested using the interface earlier in the other threads and I had come across the same idea on StackOverflow earlier in the day and thought it was a reasonably elegant way to emulate const correctness in C#. However, it turns out to be more work than it should be for something so fundamental to helping the compiler understand the orginal programmers intentions IMHO.

C# had been nothing more than a curiosity to me until recently as I stuck with C/C++ all these years but now that I've attempted to write a few small but serious apps with C#, I'm realizing it's really lacking in some important ways. I've read the posts, blogs, and documentation defending some of the design decisions but I've seen some good counter arguments as well.

Anyway, enough of my ranting. I'll probably need to work with it some more before getting too critical of it. Sigh | :sigh:
thanks for the advice.
GeneralRe: Equivalent way to achieve const or readonly return type from method Pin
RobCroll27-Jan-11 18:55
RobCroll27-Jan-11 18:55 
GeneralRe: Equivalent way to achieve const or readonly return type from method Pin
Bernhard Hiller28-Jan-11 1:24
Bernhard Hiller28-Jan-11 1:24 
GeneralRe: Equivalent way to achieve const or readonly return type from method Pin
bob1697228-Jan-11 3:08
bob1697228-Jan-11 3:08 
AnswerRe: Equivalent way to achieve const or readonly return type from method Pin
TheGreatAndPowerfulOz28-Jan-11 7:38
TheGreatAndPowerfulOz28-Jan-11 7:38 
QuestionAccessviolationException was unhandled when doing SendMessage to get DeviceArrival message upon startup of program [modified] Pin
Blubbo27-Jan-11 2:24
Blubbo27-Jan-11 2:24 
AnswerRe: AccessviolationException was unhandled when doing SendMessage to get DeviceArrival message upon startup of program Pin
RaviRanjanKr27-Jan-11 2:42
professionalRaviRanjanKr27-Jan-11 2:42 
GeneralRe: AccessviolationException was unhandled when doing SendMessage to get DeviceArrival message upon startup of program Pin
Blubbo27-Jan-11 2:53
Blubbo27-Jan-11 2:53 
AnswerRe: AccessviolationException was unhandled when doing SendMessage to get DeviceArrival message upon startup of program Pin
Luc Pattyn27-Jan-11 3:00
sitebuilderLuc Pattyn27-Jan-11 3:00 
GeneralRe: AccessviolationException was unhandled when doing SendMessage to get DeviceArrival message upon startup of program Pin
Blubbo27-Jan-11 2:58
Blubbo27-Jan-11 2:58 
AnswerRe: AccessviolationException was unhandled when doing SendMessage to get DeviceArrival message upon startup of program Pin
Luc Pattyn27-Jan-11 3:08
sitebuilderLuc Pattyn27-Jan-11 3:08 
GeneralRe: AccessviolationException was unhandled when doing SendMessage to get DeviceArrival message upon startup of program Pin
Blubbo27-Jan-11 3:24
Blubbo27-Jan-11 3:24 
AnswerRe: AccessviolationException was unhandled when doing SendMessage to get DeviceArrival message upon startup of program Pin
Luc Pattyn27-Jan-11 3:39
sitebuilderLuc Pattyn27-Jan-11 3:39 
AnswerRe: AccessviolationException was unhandled when doing SendMessage to get DeviceArrival message upon startup of program Pin
Alan N27-Jan-11 3:20
Alan N27-Jan-11 3:20 
GeneralRe: AccessviolationException was unhandled when doing SendMessage to get DeviceArrival message upon startup of program Pin
Blubbo27-Jan-11 6:43
Blubbo27-Jan-11 6:43 
GeneralRe: AccessviolationException was unhandled when doing SendMessage to get DeviceArrival message upon startup of program Pin
Blubbo27-Jan-11 6:57
Blubbo27-Jan-11 6:57 
AnswerRe: AccessviolationException was unhandled when doing SendMessage to get DeviceArrival message upon startup of program Pin
_Erik_27-Jan-11 5:39
_Erik_27-Jan-11 5:39 
QuestionZoom in on a label without changing the font size [modified] Pin
Lee Reid27-Jan-11 0:57
Lee Reid27-Jan-11 0:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.