如何在列表中显示该列表项目在C#console中的内容的描述

发布于 2025-02-01 16:33:24 字数 162 浏览 5 评论 0原文

我正在尝试显示一个以降序排序的列表,其中每个项目正在显示,并描述该项目在VS Console应用中的价值。我只是不确定如何使用每个项目显示描述

。输出: 每月总费用//列表的说明项目:$ 1000 //从列表获得并分类的项目 房屋贷款还款:700美元 车辆分期付款:$ 300

谢谢

I am trying to display a list sorted in descending order with each item being displayed with a description of what the value of the item is in VS console app. I’m just not sure how to display the description with each item

Eg. output:
Total monthly expenses//description of list item : $1000//item obtained from list and sorted
Home loan repayment: $700
Vehicle Installment: $300

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱已欠费 2025-02-08 16:33:24

我看不到您从哪里获得描述值。这样做的更好方法是使用字典而不是列表。

double cost = textbox1.Text; // cost of item
string des = textbox2.Text; //description of item

//below code goes into a event to add each item cost+description
Dictionary<double, string> io = new Dictionary<double, string>();
io.Add(cost, des);

//below code goes into a event to display all items
foreach(KeyValuePair<double, string> val in io.OrderByDescending(i => i.Key)) {
Console.WriteLine("${0},{1}", val.Key, val.Value);
}

I cannot see where you are getting the description values from. A better way to do this would be to use Dictionary instead of a List.

double cost = textbox1.Text; // cost of item
string des = textbox2.Text; //description of item

//below code goes into a event to add each item cost+description
Dictionary<double, string> io = new Dictionary<double, string>();
io.Add(cost, des);

//below code goes into a event to display all items
foreach(KeyValuePair<double, string> val in io.OrderByDescending(i => i.Key)) {
Console.WriteLine("${0},{1}", val.Key, val.Value);
}
伊面 2025-02-08 16:33:24

假设您已经从数据库中获取了数据,请将数据存储在字典集合中。字典集的键值对中的键是产品描述信息,值是特定的价格。您可以首先提取字典集中的键值进行排序,然后根据键值在字典集中提取值值。

static void main(string[] args)
{
    Dictionary<string, int> d = new Dictionary<string, int>();

    d.Add("keyboard", 100);
    d.Add("mouse", 80);

    //get key
    var val = d.Keys.ToList();

    //sort
    val.Sort();

   
    foreach (var key in val)
    {
        Console.WriteLine(key);
    }
}

assuming you have fetched the data from the database, store the data in a dictionary collection. The key in the key-value pair of the dictionary set is the product description information, and the value is the specific price. You can first extract the value of the key in the dictionary set for sorting, and then extract the value value in the dictionary set according to the value of the key.

static void main(string[] args)
{
    Dictionary<string, int> d = new Dictionary<string, int>();

    d.Add("keyboard", 100);
    d.Add("mouse", 80);

    //get key
    var val = d.Keys.ToList();

    //sort
    val.Sort();

   
    foreach (var key in val)
    {
        Console.WriteLine(key);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文