Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Read only Members of C sharp

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 25-01-2010
Member
 
Join Date: Dec 2009
Posts: 32
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.
Reply With Quote
  #2  
Old 25-01-2010
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
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.
Reply With Quote
  #3  
Old 25-01-2010
Member
 
Join Date: May 2008
Posts: 1,990
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.
Reply With Quote
  #4  
Old 25-01-2010
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
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.
Reply With Quote
  #5  
Old 25-01-2010
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,267
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:
using System;
class Circle1
{
private const double pi1=3.14;
public readonly int radius1; //declaration of a Readonly Member

public Circle(int r1)
{
radius = r1;

}
public double Area1()
{
return pi1 * radius1 * radius1;
}
}

class Test1
{
public static void Main(String [] args)
{
Circle c1 = new Circle1(10);
Console.WriteLine(c1.Area1());
}
}
Reply With Quote
  #6  
Old 25-01-2010
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,299
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 04:06 AM.