|
-
September 1st, 2011, 05:52 PM
#1
declaring a const object in C#
Folks,
I used to be an enthusiastic C++ writer. Currently, I’m going up the learning curve of .NET and C#.
From what I’m reading on the web, only the C# built-in types may be declared as const. Is there a workaround that would allow to declare a constant local object variable, an instance of a framework class?
Code:
private void foo()
{
const Size sz = new Size(19, 16); // this doesn’t work in C#
// ...
}
Any suggestion, insight or reference is really appreciated!
- Nick
P.S. It would be lamentable, if designers of C# just decided not to implement the const facilities of C++ (which were well thought through, IMHO).
Last edited by kender_a; September 1st, 2011 at 07:41 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|