如何将所有变量值推送到列表

时间:2019-02-13 03:04:51

标签: c#

如何将所有_aa值推送到_lZip?

我有一个Zip类别,如下所示:

public class Zip
{
    public string Country_Code { get; set; }
    public string State_Code { get;  set; }
    public string City { get; set; }
    public string Zip_Code { get; set; }
}

下面有一个分组列表:

var _aa  = _f.GroupBy(o => new { o.properties.Country, o.properties.State, 
                o.properties.County, o.properties.City, o.properties.zipCode 
              })
                                    .Select(group => new
                                    {
                                        Country_Code = group.Key.Country,
                                        State_Code = group.Key.State,
                                        City = group.Key.City,
                                        Zip_Code = group.Key.zipCode
                                    }).ToList();

我的问题是:如何将_aa值推入_lZips?

我尝试过:

_lZips = List<Zip>_aa;

但是它给了我下面的错误:

  

错误CS0305使用通用类型“列表”需要1种类型   争论

1 个答案:

答案 0 :(得分:3)

您是否要以Zip类型返回结果?如果是,只需在select中创建新的Zip实例:

using Microsoft.Graph;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            HttpClient httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            UserCreation uc = new UserCreation
            {
                accountEnabled = true,
                displayName = "cyril testgraphh",
                mailNickName = "cyriltestgraphh",
                passwordProfile = new PasswordProfile { ForceChangePasswordNextSignIn = false, Password = "Password!" },
                userPrincipalName = "XXXXXX@jmaster.onmicrosoft.com"
            };
 
            string json = JsonConvert.SerializeObject(uc);
            var content = new StringContent(json, Encoding.UTF8, "application/json");
 
            HttpResponseMessage response = httpClient.PostAsync("https://graph.microsoft.com/v1.0/users", content).Result;
            Console.Write(response);
            Console.ReadLine();
        }
    }
    class UserCreation
    {
        public bool accountEnabled { get; internal set; }
        public string displayName { get; internal set; }
        public string mailNickName { get; internal set; }
        public string userPrincipalName { get; internal set; }
        public PasswordProfile passwordProfile { get; internal set; }
    }
 
}