c#无法将’System.Windows.Forms.Label’类型的对象强制转换为’System.Windows.Forms.TextBox’

c#无法将’System.Windows.Forms.Label’类型的对象强制转换为’System.Windows.Forms.TextBox’,第1张

概述我无法找到解决此错误的任何内容:/我尝试将2个字母组合(例如aa,ba,cb)设置为乘数(aa * 3 = 4 * 3 ba * 2 = 3,5 * 2).  我的代码是; string[] dersler = new string[9]; double[] kredi = new double[9]; double[] krediSonuclari = new double[9] 我无法找到解决此错误的任何内容:/我尝试将2个字母组合(例如aa,ba,cb)设置为乘数(aa * 3 = 4 * 3 ba * 2 = 3,5 * 2).
 我的代码是;

string[] dersler = new string[9];    double[] kredi = new double[9];    double[] kredisonuclari = new double[9];    double derscarp(double s1,double s2)    {        return s1 * s2;    }    private voID button1_Click(object sender,EventArgs e)    {        int i=0;        int j = 0;        foreach (TextBox item in Controls)        {            if (item.name.Substring(0,7)=="txtders")            {                dersler[i] = Convert.ToString(item.Text);                i++;            }        }        foreach (TextBox item in Controls)        {            if (item.name.Substring(0,8) == "txtkredi")            {                kredi[j] = Convert.Todouble(item.Text);                j++;            }        }        double toplam =0;        for (int k = 0; k < 9; k++)        {
解决方法
foreach (TextBox item in Controls)

控件包含一些不是文本框的控件.
您的foreach语句告诉编译器将集合中的每个项目转换为TextBox,这将无法正常工作.

相反,您可以调用.OfType< TextBox>(),它将返回仅包含TextBox实例的集合的已过滤子序列.

总结

以上是内存溢出为你收集整理的c#无法将’System.Windows.Forms.Label’类型对象强制转换为’System.Windows.Forms.TextBox’全部内容,希望文章能够帮你解决c#无法将’System.Windows.Forms.Label’类型的对象强制转换为’System.Windows.Forms.TextBox’所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1225954.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存