C#将List<string>转换为List<double>
C#基础知识点汇总之string与double相互转换
string 转 double
double 转 string
获取文本框的值
文本框更新值
更改文本框字体颜色
心得
总结
C#将List<string>转换为List<double>//string转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>转string
string douStr = string.Join(" ", douList2.ConvertAll(s => Convert.ToString(s)));//douStr : 600 650 700
C#基础知识点汇总之string与double相互转换
string 转 double
string 类型的 数字字符串,如"3.14",转换为数值:3.14
double num = Convert.ToDouble("3.14");
double total_battery_capacity = Convert.ToDouble(this.txtbox_battery_totoal_capacity.Text);
double 转 string
double 是数值,如3.14,转换为:“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 没有括号
文本框更新值如把 “hello world” 设置到文本框
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#快速做小工具,应用开发很简单
界面可以做的很美观,功能强大
总结以上为个人经验,希望能给大家一个参考,也希望大家多多支持软件开发网。