我正在编写一个保存字符串数组的应用程序,但我遇到了麻烦,因为它有很多规范,对我来说似乎很复杂。
需要这样做:
有人有建议吗?
string[] locations = {"", "", "", "", "", ""};
int locationCount = 0;
if (locationCount >= 6)
{
locationCount = 0;
}
locations[locationCount] = full;
locationCount++;
for (int i = 0; i < 6; i++)
{
if (locations[i] == "")
{
if (locationString.Split('/').Length > 6)
{
locationString += locations[i] + "/";
}
}
}
答案 0 :(得分:0)
为了保存您想要的数据,您将不得不使用某些静态变量,您将无法将其全部保存在您的方法中。
也许这样的事情对你有用:
public class Locations
{
private static string[] _locations = {"", "", "", "", "", ""};
private static int _currentLocation = 0;
public static void Iterate(string data)
{
foreach(var item in data.split('/'))
{
_locations[_currentLocation++] = item;
if(_currentLocation == 6)
{
//Save Data
_currentLocation = 0;
}
}
}
}