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's typical about a windows process in regards to memory allocation in .net?
What is .net environment?
What's singleton activation mode in .net?
What data providers available in .net to connect to database?
What does cil do?
What is .net code security?
What is file extension of Webservices in .Net?
Please explain what are an inheritance, polymorphism, and encapsulation?
What is the difference between a namespace and assembly name in .net?
What does mean by .net framework?
What is an anonymous method and how is it different from a lambda expression?
Which namespace is require to used XML in .NET?
Please explain what is heap and what is stack?
Explain what is the difference between web application and enterprise application?
What is the transport protocol you use to call a seb service soap?