簡體   English   中英

從 DTO 列表中獲取項目

[英]Get item from list of a DTO

OnInitializedAsync 我通過 http 請求獲得了我的客戶列表。 它將一項加載到列表中。 我怎樣才能把這個項目放到我的另一個變量中? 代碼如下。

    private List<CustomerDTO> customers { get; set; }
    private CustomerDTO customer { get; set; } = new();

    protected override async Task OnInitializedAsync()
    {
        customers = await httpClient.GetFromJsonAsync<List<CustomerDTO>>(TestRoutes.Customer.GET_Customers());
        customer = ?
    }

在評論中澄清后,我嘗試使用customer = customers.FirstOrDefault(x => x.Id == <insert Id here>);

當然,我沒有可比較的 ID。 所以正如評論中提到的@John,我使用了customer = customers.First(); 從列表中獲取該單個客戶

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM