-
-
Save Ninputer/3206024 to your computer and use it in GitHub Desktop.
递归创建List并填充值
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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