简体   繁体   English

如何在最后列表中插入元素?

[英]How insert element in last list?

I have a list m . 我有一个清单m I want to insert an element to the end of this List . 我想在此List的末尾插入一个元素。 Please tell me how I can do this. 请告诉我如何做到这一点。

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 

m.Add(7); will add it to the end of the list. 将它添加到列表的末尾。

What you are doing is trying to call the method Add on a double 你正在做的是尝试调用方法Add on a double

Use: 采用:

List<double> m = new List<double>();
m.Add(1);
m.Add(2);
m.Add(3);
m.Add(7);

you should use the Add method. 你应该使用Add方法。

Example : 示例:

m.Add(7);

This Example shows you how to add elements to the List and how to print them. 示例显示如何向List添加元素以及如何打印它们。

You can use List<T>.Add() method. 您可以使用List<T>.Add()方法。 Like; 喜欢;

Adds an object to the end of the List. 将对象添加到List的末尾

List<double> m = new List<double>();
   m.Add(1);
   m.Add(2);
   m.Add(3);
   m.Add(7);

Here is a DEMO . 这是一个DEMO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM