简体   繁体   中英

How insert element in last list?

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.

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:

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

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.

Example :

m.Add(7);

This Example shows you how to add elements to the List and how to print them.

You can use List<T>.Add() method. Like;

Adds an object to the end of the List.

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

Here is a DEMO .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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