Autor Beitrag
Jan85
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mo 09.06.08 15:34 
ich schreibe ein Programm das, wenn eine textbox leer gelassen wird, so weiterrechnen soll wie wenn eine 0 drin steht.

dies ist mein versuch, der aber nicht klappt. Wäre super wenn mir jemand helfen könnte.

[cs]if (textBox3.Text == "") textBox3.Text=0.ToString();
bakachan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 503
Erhaltene Danke: 34

W7 (x64) Ultimate
C# / VB.NET (VS2010 Ultimate)
BeitragVerfasst: Mo 09.06.08 15:39 
ausblenden C#-Quelltext
1:
2:
if(string.IsNullOrEmpty(textBox3.Text))
    textBox3.Text = "0";
Jan85 Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mo 09.06.08 16:41 
Nun kommt bei mir die Fehlermeldung 'string' does not contain a definition for 'IsNullOrEmpty'

Hier mal mein kompletter Quelltext

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
 {  float Zahl1=float.Parse(textBox1.Text);
    float Zahl2=float.Parse(textBox2.Text);
    float Zahl3=float.Parse(textBox3.Text);
    float Ergebnis=(Zahl1+Zahl2+Zahl3);
      
    if(string.IsNullOrEmpty(textBox3.Text))  
        textBox3.Text = "0"

    if (radioButton1.Checked)
    label2.Text=(Ergebnis*7).ToString();
    else if (radioButton2.Checked)
    label2.Text=(Ergebnis*5/8).ToString();
          }
bakachan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 503
Erhaltene Danke: 34

W7 (x64) Ultimate
C# / VB.NET (VS2010 Ultimate)
BeitragVerfasst: Mo 09.06.08 16:45 
den Codeschnippsel den ich gepostet habe habe ich getestet, er funktioniert.

und string.IsNullOrEmpty ist eine gültige Methode im .net-Framework2.0

ich weiss nicht was du anderes verwendest aber bei mir kommt keine Fehlermeldung also kann ich es auch nicht nachvollziehen