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(); } }
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.
ReplyDeleteBut 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();
}
}