|
| |||||||||
| Tags: c sharp, c sharp members, read only, read only members, read only variables |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Read only Members of C sharp
Hello friends, I am studying C sharp programming language. I know that C sharp is based on .Net framework. But there is one concept in C sharp is quit difficult to understand and which is read only members. I don't have idea about the use of read only members of C sharp. I wonder if you are able to provide me some details over read only members of C sharp. I would greatly appreciate you help over this. |
|
#2
| ||||
| ||||
| Re: Read only Members of C sharp
The constructor is a good place to initialize a read only variable. read only variables need not to be initialized when declared. It is optional for read only members to be initialized when they are declared and read only members can be initialized only once in a class. The const variable must be initialized when it is declared. So it's a syntax error for a const members value to change. Variables that must not be modified must use the const or read only keywords.It is assumed that a const member is static. So, a const member has class wide scope. |
|
#3
| |||
| |||
| Re: Read only Members of C sharp
The read only modifier of C sharp is basically used for the declaration of the constant data member in a class. The read only modifier extends the const modifier by allowing the data member to be initialized in any class constructor. It is optional for read only members to be initialized when they are declared. If the const is not initialized along with the declaration, the compiler will generate an error. It provides flexibility than using the const modifier. The const modifier implicitly defines the data member as static, and must be initialized along with its declaration. |
|
#4
| ||||
| ||||
| Re: Read only Members of C sharp
The read only Members of C sharp used to make an specific data member. In C sharp read only can be used to set dynamic value. Read only members can be initialized with an expression at run time. In C sharp A read only modifier specifies that the member can have its value set once only, This doesn’t mean that a read only data member cannot be static, simply it must explicitly be declared. |
|
#5
| ||||
| ||||
| Re: Read only Members of C sharp
Hello friends, Please refer following C sharp example which shows how to declare read only members of C sharp. Quote:
|
|
#6
| ||||
| ||||
| Re: Read only Members of C sharp Read only member of C sharp is initialized within a member of class and which is not a constructor. This read only members doesn't need to be initialized when declared. Read only members of C sharp language can be initialized at compile time.It is optional for read only members to be initialized when they are declared and read only members can be initialized only once in a class. I hope from this information you will get some idea about Read only Members of C sharp. |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Read only Members of C sharp" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Listing members of Group with >1500 members | Umesh Thakur | Windows Server Help | 11 | 1 Week Ago 05:29 AM |
| Display members of a group with more than 1500 members | Simon G | Windows Server Help | 5 | 25-10-2011 01:35 PM |
| Sharp 007SH Hybrid An 3D Clamshell Android Phone by Sharp | jackalz | Web News & Trends | 3 | 22-05-2011 08:28 AM |
| Can copy and read the new files but cannot read or delete old contents in the hard drive | GOOL | Hardware Peripherals | 3 | 14-12-2010 04:10 AM |
| How to toggle between read-only and read-write in Word 2007 | Avogadro | MS Office Support | 2 | 13-02-2008 04:26 AM |