How to convert short?[ ] to string[ ]
-
I have an array full of values of type short?[] and want to display them in a MultiLine Textbox which requires values of type string[]. I can not figure out how to convert between the two value types. Here is my code that I thought would work but I get error - "can not convert type short?[] to string[] "
NumArray = new short?[37]; public void SetFormData() { textbox1.Lines = new string[37] ; textbox1.Lines = (string[])NumArray; }
Haz
-
I have an array full of values of type short?[] and want to display them in a MultiLine Textbox which requires values of type string[]. I can not figure out how to convert between the two value types. Here is my code that I thought would work but I get error - "can not convert type short?[] to string[] "
NumArray = new short?[37]; public void SetFormData() { textbox1.Lines = new string[37] ; textbox1.Lines = (string[])NumArray; }
Haz
You can't convert like that. Try this:
string[] stringArray = new string[37];
for(int i=0; i<37; i++)
{
short? num = NumArray[i];
if (num != null)
stringArray[i] = NumArray[i].ToString();
else
stringArray[i] = ""; // Or what ever else you want in place of null
}
textbox1.Lines = stringArray;
Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
You can't convert like that. Try this:
string[] stringArray = new string[37];
for(int i=0; i<37; i++)
{
short? num = NumArray[i];
if (num != null)
stringArray[i] = NumArray[i].ToString();
else
stringArray[i] = ""; // Or what ever else you want in place of null
}
textbox1.Lines = stringArray;
Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog