c# - Assigning first row from a generic list to an Object -


i have generic list<somecode> list containing multiple values.

i trying pass first row in list object as:

if(list.count==1)     somecode sc = list[0]; 

can please tell me why happening?

here class

public class somecode {     private int _somecodeid;     private string _somecodeescription;     private string _somecode;      public int somecodeid     {         { return _somecodeid; }         set { _somecodeid = value; }     }      public string somecodedescription     {         { return _somecodeescription; }         set { _somecodeescription = value; }     }      public string code     {         { return _somecode; }         set { _somecode = value; }     } } 

i populate list list list. method contains object somecode sc = new somecode

now when assign first row object

if(list.count==1)     somecode sc = list[0]; 

then values assigned except code.

it takes items in list except first one. first item gets printed this:

"sc.somecode= somecode"s 

however other values added sc.somecodedescription = "hello"; etc

when explicitly assign values, works:

sc.firstitem = list[0].firstitem 

try overloading "=" operator , assign matching values. http://msdn.microsoft.com/en-us/library/aa288467(v=vs.71).aspx


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -