C# program to show how we can use structure in a class

Category > CSHARP || Published on : Thursday, November 5, 2020 || Views: 461 || structure in a class


Here Pawan Kumar will explain how to show how we can use structure in a class

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication11
{
    struct Student
    {
        int rollno;
        string name;
        public void SetData(int r, string n)
        {
            rollno = r;
            name = n;
        }
        public void ShowData()
        {
            Console.WriteLine("ROLL NO=:" + rollno);

            Console.WriteLine("Name=:" + name);
        }

    }
    class struc
    {
        static void Main(string[] args)
        {
            Student s = new Student();
            s.SetData(52, "Tanmay Baid");
            s.ShowData();
            Console.ReadLine();
        }
    }
}