第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

按升序排列列表框

按升序排列列表框

C#
白衣非少年 2021-11-14 14:39:55
大家好,我是 C# 新手,我真的可以在這里使用一些幫助。我希望按照從高到低的順序排列我的列表框中的項目,反之亦然(它們是利率)我嘗試了多種使用數(shù)組的方法,但似乎都不起作用。我可以請一些幫助。我目前的代碼供參考:
查看完整描述

3 回答

?
天涯盡頭無女友

TA貢獻1831條經(jīng)驗 獲得超9個贊

最好Dictionary用他的匯率存儲銀行名稱


var dict = new Dictionary<string, string>();

dict.Add("HSBC","1.58%");

//so on

接下來,要訂購費率,您只需按價值訂購


var dictOrdered = dict.OrderByDescending(x=> x.Value);

然后將每個項目添加Dictionary到ListBox


    foreach(KeyValuePair<string, string> entry in dictOrdered)

    {

        listBox1.Items.Add($"{entry.Key} \t\t {entry.Value}");

    }

這適用于您的情況,通過比較string,但通常是正確的方法:您必須double在比較之前將值轉(zhuǎn)換為


    //highest to low

    var dict = new Dictionary<string, string>();

dict.Add("HSBC","1.58%");

    var dictOrdered = dict.OrderByDescending(x=> double.Parse(x.Value.TrimEnd( new char[] { '%' })));



查看完整回答
反對 回復(fù) 2021-11-14
?
猛跑小豬

TA貢獻1858條經(jīng)驗 獲得超8個贊

您可以采取的解決此問題的方法是:


namespace Group_Project_Final

{

    public partial class Form2 : Form

    {

        Dictionary<string, double> interestRates;


        public Form2()

        {

            InitializeComponent();

        }


        private void button1_Click(object sender, EventArgs e)

        {

            interestRates = new Dictionary<string, double>();

            interestRates.Add("DBS", 1.60);

            interestRates.Add("OCBC", 1.65);

            interestRates.Add("UOB", 1.55);

            interestRates.Add("May Bank", 1.62);

            interestRates.Add("HSBC", 1.58);

            interestRates.Add("RHB", 1.68);


            listBox1.Items.Clear();

            listBox1.Items.Add("Bank\t\tRates");

            foreach(KeyValuePair<string, double> entry in interestRates)

            {

                listbox1.Items.Add($"{entry.Key}\t\t{entry.Value:0.##}%");

            }


        }


        private void checkBox1_CheckedChanged(object sender, EventArgs e)

        {

            //order interest rates either from high to low (descending)

            interestRates.OrderByDescending(item => item.Value);

            //or from low to high

            interestRates.OrderBy(item => item.Value);

        }

    }

}


查看完整回答
反對 回復(fù) 2021-11-14
?
泛舟湖上清波郎朗

TA貢獻1818條經(jīng)驗 獲得超3個贊

項目按您添加的順序顯示,因此您應(yīng)該先訂購,然后按該順序添加。


查看完整回答
反對 回復(fù) 2021-11-14
  • 3 回答
  • 0 關(guān)注
  • 171 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號