I have some code that looks something like this.
public class CLASS
{
public string firstprop {get; set;}
public List
}
now I could easily add a value to CLASS.firstprop = "mystring";
but when trying to add a value to CLASS.secondprop = "mystring"
it wont work I get a null exception.
I am trying to consume an xml file and fill the class with the data.
of course this is just thrown together code this is not what my code specifically looks like but it is close enough to get a good idea of what may be going wrong.
I am using a XMLReader to cycle through the XML file to get the data and it will get everything except it blows up when it gets to the list part
VulpesPosted Sep 27, 2011, 6:40 PM
scott griffinPosted Sep 28, 2011, 9:51 AM
VulpesPosted Sep 28, 2011, 4:43 AM
public class CLASS
{
public string firstprop {get; set;}
public List
public CLASS()
{
secondprop = new List
}
}
You could then just do:
CLASS c = new CLASS();
c.secondprop.Add("mystring");
As long as you don't subsequently set secondprop to null, that will continue to work.
Hemant KumarPosted Sep 28, 2011, 2:09 AM
public class CLASS
{
public string firstprop {get; set;}//This is a Property of type String.Here you can set only one value
public List
}
Please do like this
1. Create a object to that Class
CLASS objClass=new CLASS();
objClass.Add("Hemant");
objClass.Add("Kumar");.
scott griffinPosted Sep 27, 2011, 6:50 PM
I have not been able to find anything that was as clear as what you just suggested. I get off work in 4 hours and when I get home that is the first thing I am going to try.
Thank you so much