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 |
Different levels of priority provided by .net.
What is web.config in .net?
If you are executing these statements in commandobject. Select * from table1; select * from table2? How you will deal result set? 42. How do you sort a dataset.
How anonymous method is different from a lambda expression?
What is an Exception? How many exceptions exist in Dot net and explain them?
What are Sessions?
Explain .net framework overview?
What is the standard you use to wrap up a call to a Web service
What is difference between .net core and .net standard?
What are the different types of memory in .net?
WHAT IS .net
i have 2 functions, int add(int a,int b); double add(int a,int b); does this code implement overloading? if not what will be the error?