Properties provide the opportunity to protect a field in a class by reading and writing to it through the property.In other languages,this is generally able by programs implementing specialized getter and setter methods. C# backdrop accredit this blazon of aegis while aswell absolution you admission the acreage just like it was a field.
Example:
using System;
public class Customer
{
private int m_id = -1;
public int GetID()
{
return m_id;
}
public void SetID(int id)
{
m_id = id;
}
private string m_name = string.Empty;
public string GetName()
{
return m_name;
}
public void SetName(string name)
{
m_name = name;
}
}
public class CustomerManagerWithAccessorMethods
{
public static void Main()
{
Customer cust = new Customer();
cust.SetID(1);
cust.SetName("Amelio Rosales");
Console.WriteLine(
"ID: {0}, Name: {1}",
cust.GetID(),
cust.GetName());
Console.ReadKey();
}
}
Interview Questions: Implement Same Name Method of two Interfaces in a Class using C#
-
This is most famous question in OOPs programming. if you have two
interfaces and driving a class and these two interfaces have the same name
method then ...
0 comments:
Post a Comment