无法将类型为"System.String []"的对象强制转换为"System.IConvertible"类型

0 .net c#

string[] weight = txtProductOptn1.Text.Split(',');
var Weight1 = Convert.ToInt32(weight);
Run Code Online (Sandbox Code Playgroud)

当我将字符串数组转换为int或decimal时,会出现错误

无法将类型为"System.String []"的对象强制转换为"System.IConvertible".

请找到答案.

Sat*_*pal 6

试试这个,weight是一个数组.假设您要转换数组的第一个元素.

string[] weight = txtProductOptn1.Text.Split(',');
var Weight1 = Convert.ToInt32(weight[0]);
Run Code Online (Sandbox Code Playgroud)