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
Explain about .net assemblies?
Compare client server application with n-tier application
what is dotnet architecture? can anyone explain that.
What is WSDL? Explain its architecture?
Explain what is mutex?
Difference between abstract class and interface in .net?
How many namespaces are in .net version 1.1?
What is typical about a windows process in regards to memory allocation in .net?
How can you turn-on and turn-off cas?
Explain what are the deferred execution and the immediate execution in linq?
What is the difference between response.redirect & server.transfer?
What is the difference between encrypting a password and applying a hashing?
Is .net core the future?
Explain how com+ related to the dna architecture?
Explain about the features and elements present in Visual studio.NET IDE?