I have faced an Stackoverflow when I run this code
class Students
{
public int SID { get { return SID; } set { SID = value; } }
public string SName { get { return SName; } set { SName = value; } }
}
The problem is located in foreach(string s in names).. I could not store the string array into my datastructure thanks in advance
class Program
{
static void Main(string[] args)
{
List<Students> sList = new List<Students>();
string[] names = new string[5] {"Matt", "Joanne", "Robert"};
System.Console.WriteLine("{0} words in text:", names.Length);
foreach (string s in names)
{
Students st = new Students();
st.SName = s;
sList.Add(st);
System.Console.WriteLine("test{0}",s);
}
foreach (Students sn in sList) Console.WriteLine(sn);
Console.ReadLine();
}
}