Add new item to List object C#

后端 未结 4 1422
灰色年华
灰色年华 2021-01-16 09:33

I want to add new object to a list: My code:

List abc = new List();
abc.Add(new geo_tag() { latitude = 111, longitude = 122, un         


        
4条回答
  •  灰色年华
    2021-01-16 10:18

    The object initializer syntax you are using came with C# 3.0. For 2.0 you have to use

    List abc = new List();
    geo_tag tag = new geo_tag();
    tag.latitude = 111;
    tag.longitude = 122;
    tag.unit = "SSS";
    abc.Add(tag); 
    

提交回复
热议问题