c# - collection list and gridview -


i want add mark1,mark2,mark3,mark4,mark5 , assign sum show in gridview.

i want add marks through function , assign sum property. how it? thanks

public partial class form1 : form {     public form1()     {         initializecomponent();     }      private void procees()     {                     list<student> ml= new list<student>();          student s1 = new student() {             name = "ram",              id = "gn01",              mark1 = 90,              mark2 = 89,             mark3 = 75,             mark4 = 45,             mark5 = 65,             sum = ""          };         ml.add(s1);          datagridview1.datasource = ml;      }       private void button1_click(object sender, eventargs e)     {         procees();     }  }   public class student  {      private string name;       public string name      {          { return name; }          set { name = value; }      }       private string id;       public string id      {          { return id; }          set { id = value; }      }       private int mark1;       public int mark1      {          { return mark1; }          set { mark1 = value; }      }      private int mark2;       public int mark2      {          { return mark2; }          set { mark2 = value; }      }      private int mark3;       public int mark3      {          { return mark3; }          set { mark3 = value; }      }      private int mark4;       public int mark4      {          { return mark4; }          set { mark4 = value; }      }      private int mark5;       public int mark5      {          { return mark5; }          set { mark5 = value; }      }      private int sum;       public int sum      {          { return sum; }          set { sum = value; }      }  } 

remove private field 'sum':

 private int sum; 

let pubic property 'sum' calculate sum:

 public int sum  {      { return mark1 + mark2 + mark3 + mark4 + mark5; }  } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -