Home > Article > Backend Development > C# method to dynamically add new elements to an array
Often during development, the string will be split. After getting the array, do the corresponding things!
But sometimes, the demand determines that the length of the array is not fixed, and C# arrays do not allow dynamic addition. New elements...
I have been struggling with this matter for a while!! God has a vision the day after tomorrow! There is a solution!
How to dynamically add it to the array? At this time we have to use List
Look at the following code:
string[] KTCodes = new string[0]; //机型逗号拆分 List<string> ktls = KTCodes.ToList(); ktls.Add(SVKTCode); KTCodes = ktls.ToArray();
Such a conversion can achieve the effect of dynamically adding new elements
For more related articles on how to dynamically add new elements to C# arrays, please pay attention to the PHP Chinese website!