converting from a string array to an int array in C #
String[] input = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
int[] output = array.convertall<string, int> (Input, delegate (string s)
{
return int. Parse (s);
});
Note:
Convert using the static generic method ConvertAll in the array class
Delegate (string s) {return int. Parse (s); }
This sentence means: Establish an anonymous delegate, the method body associated with the delegate is: return int. Parse (s);
Casts each string in the array to reshape and returns the add to output
How to convert a string array to an int array in C #
string[] Strarray = "A,b,c,d,e,f,g". Split (New char[]{', '});
Int[] Intarray;
C # 3.0 Use this sentence
Intarray = array.convertall<string, int> (strarray, s = = int). Parse (s));
2.0 Replace the previous example with the following statement.
Intarray = array.convertall<string, int> (Strarray, delegate (string s) {return int. Parse (s); } );
conversion between list〈string〉 and string[] arrays in C #
1, from system.string[] go to list<system.string>
system.string[] str={"str", "String", "abc"};
list<system.string> lists=new list<system.string> (str);
2, transfer from list<system.string> to system.string[]
List<system.string> lists=new list<system.string> ();
Lists.add ("str");
Lists.add ("Hello");
System.string[] Str=lists.toarray ();
The test is as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Namespace ConsoleApplication1
{
Class Program
{
static void Main (string[] args)
{
System.string[] SA = {"str", "string1", "Sting2", "abc"};
list<system.string> SL = new list<system.string> ();
for (System.Int32 i = 0; i < sa.length;i++)
{
Console.WriteLine ("Sa[{0}]={1}", I,sa[i]);
}
SL = new list<system.string> (SA);
Sl.add ("hello!");
foreach (System.String s in SL)
{
Console.WriteLine (s);
}
system.string[] nextstring = Sl.toarray ();
Console.WriteLine ("The Length of Nextstring is {0}", nextstring.length);
Console.read ();
}
}
}
C # conversion between different arrays "reprint, Digest automatic deletion"