I have the following code which create an object from array of string.
struct Item
{
public Int32 ItemID { get; }
public String ItemText { get; }
public Int32 CategoryID { get;}
public Int32 GroupID { get;}
public String LargePictureName { get; }
public Item(string[] menuItem)
{
DateTime minDateTime = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
ItemID = String.IsNullOrEmpty(menuItem[0]) ? 0 : Convert.ToInt32(menuItem[0]);
ItemText = menuItem[1];
CategoryID = String.IsNullOrEmpty(menuItem[2]) ? 0 : Convert.ToInt32(menuItem[2]);
GroupID = String.IsNullOrEmpty(menuItem[3]) ? 0 : Convert.ToInt32(menuItem[3]);
LargePictureName = menuItem[4];
But when I run this code I got an Exception "System.FormatException: 'Input string was not in a correct format.'" from this line LargePictureName = menuItem[4]; This is stack trace
Exception thrown: 'System.FormatException' in mscorlib.dll System.Transactions Critical: 0 : http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/UnhandledUnhandled exceptionAMenuImportTool.exeSystem.FormatException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Convert.ToInt32(String value) ... I confused because there is no conversion on that line. I tried debug it and found that menuItem[4] is empty string. I tried change this line to LargePictureName = "1"; but I still got the same exception. I just don't understand there is no conversion in this line but why I got an exception from conversion to Int32. Any help would be appreciated. Thanks in advance