Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

Part 29 – Difference between classes and structs






1 comment:

  1. Structure doesn’t have the concept of object reference variable and object. That’s why they don’t need to have a parameter less constructor and a destructor.

    But I'm able to create reference variable and object. Please someone explain.


    interface Person { }
    struct Student : Person
    {
    int roll;
    string firstName;
    string secondName;
    //public Student() : this("FN", "SN", 100) { }
    public Student(string FN, string LN, int R)
    {
    firstName = FN;
    secondName = LN;
    roll = R;
    }
    public void print()
    {
    Console.WriteLine("Full name is {0} & Roll No. is {1}", firstName + secondName, roll);
    }
    //~ Student() { }
    }
    class Program
    {
    static void Main(string[] args)
    {
    Student s = new Student("FirstName", "LastName", 47);
    s.print();
    Student st = new Student();
    st.print();
    }
    }

    ReplyDelete

It would be great if you can help share these free resources