Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How is a property designated as read-only?

Answers were Sorted based on User's Feedback



How is a property designated as read-only?..

Answer / om nama shivaya

Properties can be made read-only.Read only property means
the property value can not be changed . values for read
only property can be assigned through object creation.

using System;

public class Customer
{
private int m_id = -1;
private string m_name = string.Empty;

public Customer(int id, string name)
{
m_id = id;
m_name = name;
}

public int ID
{
get
{
return m_id;
}
}

public string Name
{
get
{
return m_name;
}
}
}

public class ReadOnlyCustomerManager
{
public static void Main()
{
Customer cust = new Customer(1, "Amelio Rosales");

Console.WriteLine(
"ID: {0}, Name: {1}",
cust.ID,
cust.Name);

Console.ReadKey();
}
}

Is This Answer Correct ?    0 Yes 0 No

How is a property designated as read-only?..

Answer / deep

In VB.NET:
Private mPropertyName as DataType
Public ReadOnly Property PropertyName() As DataType
Get Return mPropertyName
End Get
End Property
In C#
Private DataType mPropertyName;
public returntype PropertyName
{
get{
//property implementation goes here
return mPropertyName;
}
// Do not write the set implementation
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Dot Net General Interview Questions

Which among the following two is best and why? Abstract Class and Interface. What is the major difference in between those two except the discrete methods and methods with function definition.

4 Answers   247Customer,


How is development of a Windows service different from a Windows Forms application?

1 Answers  


Explain how to redirect tracing to a file?

0 Answers  


What are the namespace available in .net?

0 Answers  


What is .net3.0 and .net3.5?

0 Answers  


How will you register com+ services?

1 Answers  


What is a design pattern and what is it for?

0 Answers  


Writing a Stored procedure to insert the values into a table

1 Answers  


How do you generate a strong name?

0 Answers  


What is "common language specification" (cls) in .net?

0 Answers  


can any one tel me the complete Testing Procedure of any one simple PROJECT i mean either web/windows based application?

0 Answers  


What are the challenging issues you have faced in implementation project/Maintainance project in .net Functionality? How you have overcome that issue?

0 Answers   TCS,


Categories