Uploading a file via web form and parsing its contents to a list how do I allow null or empty value when parsing for C.MN,C.LN, C.Val these three are public datatypes declared like this
Namespace datatypes
Public class Uploads
{
Public long Mn {get; set;}
Public int LN { get;set }
Public int Val {Get;Set}
}
List<Uploads> CDU = new List<Uploads>();
string[] fields;
string data = read.ReadLine();
while ((data = read.ReadLine()) != null)
{
if (data.Length != 0)
{
Uploads C = new Uploads();
fields = data.Split(',');
C.LN = Convert.ToInt32(fields[0]);
C.MN = Convert.ToInt64(fields[1]);
C.Val = Convert.ToInt32(fields[2]);
CDU.Add(C);
Simply put, you have to use nullable value types, e.g.
Of course you’ll need to work out whether to give them a value or leave them as null, presumably based on whether the string is empty or not.
For example:
Or just:
As an aside, those names are completely unmaintainable. In six months, will you have any idea what they’re meant to mean?