C#如何將List<string>轉(zhuǎn)換為List<double>
C#將List<string>轉(zhuǎn)換為List<double>
//string轉(zhuǎn)List<double> List<string> strList = new List<string>(); strList.Add("100"); strList.Add("500"); strList.Add("700"); List<double> douList = strList.ConvertAll(s => Convert.ToDouble(s)); string str = "600 650 700"; List<double> douList2 = str.Split(' ').ToList().ConvertAll(s => Convert.ToDouble(s)); //List<double>轉(zhuǎn)string string douStr = string.Join(" ", douList2.ConvertAll(s => Convert.ToString(s)));//douStr : 600 650 700
C#基礎(chǔ)知識(shí)點(diǎn)匯總之string與double相互轉(zhuǎn)換
string 轉(zhuǎn) double
string 類型的 數(shù)字字符串,如"3.14",轉(zhuǎn)換為數(shù)值:3.14
double num = Convert.ToDouble("3.14"); double total_battery_capacity = Convert.ToDouble(this.txtbox_battery_totoal_capacity.Text);
double 轉(zhuǎn) string
double 是數(shù)值,如3.14,轉(zhuǎn)換為:“3.14”
string str_num = Convert.ToString(3.14); string str_battery_actual_capacity = Convert.ToString(total_battery_capacity * battery_ratio);
獲取文本框的值
C# 文本框的值為:string
string str_name = this.txtbox_battery_ratio.Text;
注意這里的Text 沒有括號(hào)
文本框更新值
如把 “hello world” 設(shè)置到文本框
this.txtbox_hello.Text = "hello world"; this.txtbox_run_power.Text = Convert.ToString(run_power);
更改文本框字體顏色
this.txtbox_life_days.ForeColor = Color.Red; this.txtbox_run_average_power.ForeColor = Color.Blue;
心得
可以使用C#快速做小工具,應(yīng)用開發(fā)很簡單
界面可以做的很美觀,功能強(qiáng)大
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
C#實(shí)現(xiàn)讀取二維數(shù)組集合并輸出到Word預(yù)設(shè)表格
這篇文章主要為大家詳細(xì)介紹了如何使用C#實(shí)現(xiàn)讀取二維數(shù)組集合并輸出到Word預(yù)設(shè)表格,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-03-03C#實(shí)現(xiàn)winform自動(dòng)關(guān)閉MessageBox對(duì)話框的方法
這篇文章主要介紹了C#實(shí)現(xiàn)winform自動(dòng)關(guān)閉MessageBox對(duì)話框的方法,實(shí)例分析了C#中MessageBox對(duì)話框的相關(guān)操作技巧,需要的朋友可以參考下2015-04-04使用C#實(shí)現(xiàn)讀取PDF中所有文本內(nèi)容
這篇文章主要為大家詳細(xì)介紹了如何使用C#實(shí)現(xiàn)讀取PDF中所有文本內(nèi)容,文中的示例代碼簡潔易懂,具有一定的學(xué)習(xí)價(jià)值,有需要的小伙伴可以了解下2024-02-02Unity編輯器預(yù)制體工具類PrefabUtility常用函數(shù)和用法
這篇文章主要為大家介紹了Unity編輯器預(yù)制體工具類PrefabUtility常用函數(shù)及用法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08