C#

C# Properties, Class & Method

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 f...

J
Joynal Abedin
4
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
J

Written by Joynal Abedin

Passionate about technology, code, and sharing knowledge.

0 Comments

Leave a Comment