提取用逗号分隔的字符串部分

coz*_*oze 0 c# string extract comma

有人可以帮助我将字符串提取到3个不同的变量中.

用户的输入将采用此格式13,G,true.我想将数字存储在a int,G中的a char和truea中string.

但我不知道如何指定逗号位置,因此逗号之前或之后的字符可以存储在另一个变量中.我不允许使用这种LastIndexOf方法.

我是编程新手.

Him*_*ere 5

string msg = "13,G,true";
var myArray = msg.Split(",");

// parse the elements
int number;
if (!Int32.TryParse(myArray[0], out number) throw new ArgumentException("Whrong input format for number");
string letter = myArray[1];
string b = myArry[2];

// or also with a boolean instead
bool b;
if (!Int32.TryParse(myArray[2], out b) throw new ArgumentException("Whrong input format for boolean");
Run Code Online (Sandbox Code Playgroud)