Skip to content

Instantly share code, notes, and snippets.

@Ninputer
Forked from anonymous/List 递归
Created July 30, 2012 10:20
Show Gist options
  • Save Ninputer/3206024 to your computer and use it in GitHub Desktop.
Save Ninputer/3206024 to your computer and use it in GitHub Desktop.
递归创建List并填充值
List<string> CreateInstanVar(int time_in_level1)
{
List<string> result = new List<string>();
for (int i = 0; i < time_in_level1; i++)
{
result.Add(String.Empty);
}
return result;
}
List<List<string>> CreateInstanVar(int time_in_level1, int time_in_level2)
{
List<List<string>> result = new List<List<string>>();
for (int i = 0; i < time_in_level2; i++)
{
result.Add(CreateInstanVar(time_in_level1));
}
return result;
}
List<List<List<string>>> CreateInstanVar(int time_in_level1, int time_in_level2, int time_in_level3)
{
List<List<List<string>>> result = new List<List<List<string>>>();
for (int i = 0; i < time_in_level3; i++)
{
result.Add(CreateInstanVar(time_in_level1, time_in_level2));
}
return result;
}
List<List<List<List<string>>>> CreateInstanVar(int time_in_level1, int time_in_level2, int time_in_level3, int time_in_level4)
{
List<List<List<List<string>>>> result = new List<List<List<List<string>>>>();
for (int i = 0; i < time_in_level4; i++)
{
result.Add(CreateInstanVar(time_in_level1, time_in_level2, time_in_level3));
}
return result;
}
//替代方案,用重载代替传入参数
//更多的以此类推
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment