jeudi 23 mars 2017

Set property default value before instantiation

I have a class named Student :

public class Student
{
    public int ID { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
}

When I create an instanse of Student class , it is null .

Student s = new Student();

" s.ID is null , s.Name is null and s.Age is null ."

I want to set a default value for Student class , so when I create instanse of it :

Student s = new Student();

" s.ID = 1 , s.Name = Parsa , s.Age = 20 "

In the other word , I want to change declaration or implementation of property getter or override it.

How can I do this ?

Thank you in Advance.





Aucun commentaire:

Enregistrer un commentaire