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

what are the Goals of the UIP Application Block?

1 Answers  


What are code contracts?

0 Answers  


How is .net core cross platform?

0 Answers  


Describe ways of cleaning up objects.

2 Answers   Wipro,


Conceptually, what is the difference between early-binding and late-binding?

0 Answers  


How many namespaces are in .net version 1.1?

0 Answers  


What do you mean by Driver Script?

0 Answers   TCS,


What is strong-typing versus weak-typing? Which is preferred?

0 Answers  


Explain clr, cts and cls?

0 Answers  


Is the COM architecture same as .Net architecture? What is the difference between them (if at all there is)?

0 Answers   Infosys,


Tell us what is json data, and what is one way that .net developers can work with json?

0 Answers  


What is meant by .Net framework?

1 Answers  


Categories