Difference between a List's Add and Append method?

后端 未结 2 1232
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 01:17

Is there a difference between the .Append() and the .Add() method for lists in C#? I tried searching in Google and in the site but to my surprise n

2条回答
  •  情歌与酒
    2020-12-31 01:38

    Add is a void.

    Append returns an IEnumerable so you can

    var x = new List();
    x.Add(1);
    x = x.Append(2).Append(3).ToList();
    

提交回复
热议问题