How is a property designated as read-only?
Answers were Sorted based on User's Feedback
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 |
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 |
Explain how to produce an assembly?
What is func in .net 3.5?
Tell us what is a sealed class?
Why did they call it .net?
What is common type system (cts)?
Explain the difference between task and thread in .net?
How viewstate is being formed and how it is stored on client in .net?
What is 'Common Type System' (CTS) in .NET?
Difference between value type & reference types ?
Without UDDI, is it possible to access a remote web service ?
1 Answers RR, TCS, Tech Mahindra,
What are the different types of remote object creation mode in .net?
what is the use of "mustinherit" keyword?