A property is like a combination of a variable and a method, and it has two methods: a
get and a set method:
C# also provides a way to use short-hand / automatic properties, where you do not have to define the field for the property, and you only have to write get; and set; inside the property.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeeDetails
{
class Program
{
static void Main(string[] args)
{
var person = new PersonDetails();
person.studentName = \"Joynal Abedin\";
person.studentSubject = \"Computer Science & Engineering\";
person.studentDetails();
Console.ReadKey();
}
}
class PersonDetails
{
public string studentName { get; set; }
public string studentSubject { get; set; }
public void studentDetails()
{
Console.WriteLine(studentName);
Console.WriteLine(studentSubject);
}
}
}
Output:
Joynal Abedin
Computer Science & Engineering
0 Comments
Leave a Comment