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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 11:45:21  来源:igfitidea点击:

How insert element in last list?

c#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.

回答by Abdusalam Ben Haj

you should use the Addmethod.

您应该使用Add方法。

Example :

例子 :

m.Add(7);

This Exampleshows you how to add elements to the Listand how to print them.

示例向您展示如何向 中添加元素List以及如何打印它们。