What is Property? Explain read only, write only and read write property with suitable example.
' Read write property Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace readWritePropertyExample
{
public class student
{
private String studentName = "";
public string sName
{
get
{
return studentName;
}
set
{
studentName = value;
}
}
}
public class readWriteProperty
{
public static void Main(String[] args)
{
Console.WriteLine("Read Write Property Simple Example");
student studentObject = new student();
// Set sName Property
studentObject.sName = "Jaydip";
// Get sName Property
Console.WrileLine("Student Name : " + studentObject.sName);
}
}
}
' Read Only property Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace readOnlyPropertyExample
{
public class student
{
private String studentName = "";
public student(String nameValue)
{
studentName = namevalue;
}
public string sName
{
get
{
return studentName;
}
}
}
public class readProperty
{
public static void Main(String[] args)
{
Console.WriteLine("Read Only Property Simple Example");
student studentObject = new student("Arpan");
// Get sName Property
Console.WrileLine("Student Name : " + studentObject.sName);
}
}
}
' Write Only property Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace writeOnlyPropertyExample
{
public class student
{
private String studentName = "";
public string sName
{
set
{
studentName = value;
}
}
public String getStudentName()
{
return studentName;
}
}
public class writeProperty
{
public static void Main(String[] args)
{
Console.WriteLine("Write Only Property Simple Example");
student studentObject = new student();
// Set sName Property
studentObject.sName = "Pratik";
Console.WrileLine("Student Name : " + studentObject.getStudentName());
}
}
}
