C# 如何在最后一个列表中插入元素?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14424329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How insert element in last list?
提问by MohammadTofi
I have a list m
. I want to insert an element to the end of this List
. Please tell me how I can do this.
我有一个清单m
。我想在 this 的末尾插入一个元素List
。请告诉我如何做到这一点。
public List<double> m = new List<double>();
m[0].Add(1);
m[1].Add(2);
m[2].Add(3);
I want the following output if I add element 7 to the end:
如果将元素 7 添加到末尾,我需要以下输出:
1 2 3 7
采纳答案by Jesper Fyhr Knudsen
m.Add(7);
will add it to the end of the list.
m.Add(7);
将其添加到列表的末尾。
What you are doing is trying to call the method Add on a double
您正在做的是尝试在 double 上调用 Add 方法
回答by devdigital
Use:
用:
List<double> m = new List<double>();
m.Add(1);
m.Add(2);
m.Add(3);
m.Add(7);
回答by Soner G?nül
You can use List<T>.Add()
method. Like;
您可以使用List<T>.Add()
方法。喜欢;
Adds an object to the end of theList.
将一个对象添加到List的末尾。
List<double> m = new List<double>();
m.Add(1);
m.Add(2);
m.Add(3);
m.Add(7);
Here is a DEMO
.
这是一个DEMO
.