Results 1 to 4 of 4

Thread: Differentiate between const and static readonly

  1. #1
    Join Date
    Sep 2009
    Posts
    135

    Differentiate between const and static readonly

    I want to know the actual differentiation between keywords 'const' and 'static readonly' in Csharp. I not able to note down points which are understandable to differentiate between the const and static readonly. I am not that good at software programming although I have studied Java earlier.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Differentiate between const and static readonly

    Even I was confused about the differentiation between the const and static readonly. I was not able to understand what is const and static readonly. To a highlight a very basic difference const and static readonly is that the const field's value is initialized at complile time while that of a static readonly field's value is initialized at run time in C sharp.

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Differentiate between const and static readonly

    C# differentiates between static readonly and const according to the time during which their individual values are set. Incase of const its field is set at the time of compiling the code and incase of static readonly its value is initialized at runtime which is after compiling the code. This thus differentiates between const and static readonly in C#.
    Last edited by Modifier; 17-11-2009 at 12:55 AM.

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Differentiate between const and static readonly

    There is not much to actually differentiate between the two except the very obvious difference where a static readonly value can be altered inside the class where it is being declared. But for const value cannot be altered at all. This is because const value is set during the compilation time whereas for a static readonly the value is during the run-time. This the difference between the two in Csharp.

Similar Threads

  1. Problem of const variable and its reference
    By KABIRA16 in forum Software Development
    Replies: 3
    Last Post: 04-09-2009, 04:45 PM
  2. How to declare const variable in C++
    By AZUL in forum Software Development
    Replies: 3
    Last Post: 02-09-2009, 06:36 PM
  3. How to call Readonly textbox in Javascript Function
    By Aldous in forum Windows Software
    Replies: 3
    Last Post: 12-08-2009, 11:39 AM
  4. How to use datagridview readonly cell
    By Ground 0 in forum Windows Software
    Replies: 3
    Last Post: 29-07-2009, 12:44 PM
  5. const Obj problem in C++
    By Archetype in forum Software Development
    Replies: 2
    Last Post: 25-10-2008, 05:58 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,573,411.39620 seconds with 17 queries