当前位置:   article > 正文

C# 基础知识点汇总:string与double相互转换_c# string转double

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#快速做小工具,应用开发很简单
  • 界面可以做的很美观,功能强大
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/228442
推荐阅读
相关标签
  

闽ICP备14008679号