How is a property designated as read-only?
Answer Posted / 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 |
Post New Answer View All Answers
Can I write my own .net host?
object is physical and class is logical..here class is not occupying any memory as our definition of class but i got a question then the class where it stores if it is not occupying any memory....
What is .net3.5?
What is the use of gacutil.exe?
Explain attributes in dot net?
What is lambda expressions in c#?
What is managed code and managed data in .net?
How do you turn off cookies for one page in your site? Give an example.
What data providers available in .net to connect to database?
How does u handle this COM components developed in other programming languages in .NET?
What is interface and abstract class in .net?
Explain boxing and unboxing in .net.
When displaying fonts, what is the difference between pixels, points and ems?
What is delegation in .net?
What is the difference between task and thread in .net?