Home > Backend Development > C#.Net Tutorial > C# method to dynamically add new elements to an array

C# method to dynamically add new elements to an array

高洛峰
Release: 2016-12-16 14:29:47
Original
2407 people have browsed it

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();
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template