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
What is the difference between override and overload in a method?
What is static constructor, when it will be fired?
What is the difference between response.redirect & server.transfer?
How do you view the methods and members of a dll?
Explain how do assemblies find each other?
which methos do you invoke on the dataadapter control to load your generated dataset with data?
What is the use of design pattern?
Is there built-in support for tracing?
What is multiThreading in .NET?
Please explain what do the terms “boxing” and “unboxing” mean?
Explain the different parts of an assembly?
Why do we use msmq?
Do you know the difference between the stack and the heap?
What is the difference between imperative and interrogative code?
What is msil, il?