c# 4.0 - IList List is null in my Composition Class .. WHY? -


i usling ilist list property list of students class in university class .. try access list in department class part of university class .. list null .. can tell reason?

namespace universitysystem {   class university : collectionbase   {     private string _uniname;     departments _depart = new departments();       public university(string un, string dn, string cp, list<student> slist)     {         this._uniname = un;         this.ced.departname = dn;         this.ced.chairperson = cp;         foreach (student s in slist)         {             list.add(s);         }     }      #region properties      public string uniname     {         { return _uniname; }         set { _uniname = value; }     }      public departments ced     {         { return _depart; }         set { _depart = value; }     }      #endregion       public class departments : collectionbase     {         private string _departname;          public string departname         {             { return _departname; }             set { _departname = value; }         }         private string _chairperson;          public string chairperson         {             { return _chairperson; }             set { _chairperson = value; }         }         public list<student> studentlistforced = new list<student>();           public departments()         {             _departname = null;             _chairperson = null;             studentlistforced = null;         }          public departments(string dn, string cp, list<student> slist)         {             this._departname = dn;             this._chairperson = cp;             foreach (student s in slist)             {                 list.add(s);             }         }          public void showdetails()         {             console.writeline("departmental info");             console.writeline("departmentname: " + _departname);             console.writeline("chairperson name: " + _chairperson);             console.writeline("student info:");             foreach (student item in list)             {                 console.writeline("name: " + item.name);                 console.writeline("deptname: " + item.regno);                 console.writeline("total marks:  " + item.totalmarksobtained);                 console.writeline("percentage:   " + item.getpercentage());             }         }     }   } } 

the main() part is

namespace universitysystem {   class program   {     static void main(string[] args)     {          list<student> slist = new list<student>();         slist.add(new student("sana", 1234, "cis", 650));         slist.add(new student("anam", 2345, "bcit", 400));         slist.add(new student("fizzza", 2670, "electrical", 670));           university u1 = new university("ned", "computer", "ukp", slist);         console.writeline(u1.ced.departname);         u1.ced.showdetails();        }   } } 

the initializing code university not store list give parameter.

try storing list in variable in either department or university object itself, , when showing details either of object can reference list, 1 stored upon creating object.

hope helps!


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -