using System;
using System.Text.RegularExpressions;namespace Sort
{
class sort
{
static void Main(string[] args)
{
int[] buff;
string str="3,8,2,45,12,75,33";
buff=StrToInt(str);
Console.WriteLine("the buff is:{0}",buff.ToString());
}
public static int[] StrToInt(string s)
{
int[] arr=null;
int i=0;
Regex regex=new Regex(",");
string[] parts=regex.Split(s); foreach(string part in parts)
{
arr[i]=Convert.ToInt32(part);
i++;
}
return arr;
}
}
} 未处理的“System.NullReferenceException”类型:未将对象引用设置到对象的实例。
arr没有被赋值.
using System.Text.RegularExpressions;namespace Sort
{
class sort
{
static void Main(string[] args)
{
int[] buff;
string str="3,8,2,45,12,75,33";
buff=StrToInt(str);
Console.WriteLine("the buff is:{0}",buff.ToString());
}
public static int[] StrToInt(string s)
{
int[] arr=null;
int i=0;
Regex regex=new Regex(",");
string[] parts=regex.Split(s); foreach(string part in parts)
{
arr[i]=Convert.ToInt32(part);
i++;
}
return arr;
}
}
} 未处理的“System.NullReferenceException”类型:未将对象引用设置到对象的实例。
arr没有被赋值.
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
int[] buff;
string str="3,8,2,45,12,75,33";
buff=StrToInt(str);
foreach(int str_buff in buff)
{
Console.WriteLine("the buff is:{0}",str_buff.ToString());
}
}
public static int[] StrToInt(string s)
{
int i=0;
Regex regex=new Regex(",");
string[] parts=regex.Split(s);
int[] arr=new int[parts.Length];
foreach(string part in parts)
{
arr[i]=Convert.ToInt32(part);
i++;
}
return arr;
}