I am reading in data from a file into a list. Once I have the data read in, I would like to split every string, and display the length of the split string. I have tried string.Length and string.Count, but nothing works. How can I find the number of elements in my split string?
Here is the section of relevant code:
string fileread = openFileDialog1.Filename; //Opens file from computer lines = System.IO.File.ReadAllLines(fileread); foreach (string line in lines) { string[] Data_array = line.Split(','); List<string> Data_list = new List<string>(); Data_list.Add(line); lbl_datacolumns.Text = Data_array.Count;//should show number of elements in Data_array } The error is: "Cannot Convert method group 'Count; to non-delegate type 'string'
Count()is a (extension) method, so you need to add parentheses to make it a method call. See Cannot convert method group 'ToList' to non-delegate type. Then you get anintthat you want to assign to astring. For that see Convert int to string? or just put the compiler error you get in your favorite web search engine.