CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    May 2001
    Location
    Silicon Valley
    Posts
    113

    Unhappy 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
  •  





Click Here to Expand Forum to Full Width

Featured