Autor Beitrag
Cisab
Hält's aus hier
Beiträge: 6


Visual Studio 2005
BeitragVerfasst: Do 16.02.06 14:36 
Hi @All,
wie bereits erwähnt bin ich C#-Noob.
Diesmal fehlt mir die Entsprechung für ein ElseIf wie man es von VB kennt. Gibt es so etwas in C# oder muß ich ein netsted IF verwenden?

Damit klar wird was ich meine ein VB-Schnippsel:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
    If iNumber < 42 Then
        Debug.Print "Die Zahl ist kleiner als 42"
    ElseIf iNumber = 42 Then
        Debug.Print "Die Zahl ist 42"
    Else
        Debug.Print "Die Zahl ist größer als 42"
    End If


Danke schon mal.

Cisab
Coreyl
ontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 26

XPP
VS 05, TextEditor
BeitragVerfasst: Do 16.02.06 14:41 
switch(); <- die klasse mal anschauen

bei einem else:

if(bla)
{}
else
{}
Cisab Threadstarter
Hält's aus hier
Beiträge: 6


Visual Studio 2005
BeitragVerfasst: Do 16.02.06 14:47 
Hi,

is nicht ganz das was ich suche, aber wird sicher auch funktionieren ist quasi das Equivalent zu nem Select in VB.

THX
Cisab
Coreyl
ontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 26

XPP
VS 05, TextEditor
BeitragVerfasst: Do 16.02.06 14:52 
du kannst doch einfach auch mehrere IFs verschachteln falls notwendig

mit einem:
break;
kommst du aus der schleife raus.

_________________
Von allen Dingen die mir Verloren gegangen, bin ich am meisten an meinem Verstand gehangen
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6386
Erhaltene Danke: 146

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 16.02.06 14:52 
Es geht auch so:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
if(bla)
{}
else
{
  if(blub)
  {}
  else
  {}
}

Das ist nicht anderes als ein ElseIf.
Ich würde aber möglichst ein switch() verwenden.
Cisab Threadstarter
Hält's aus hier
Beiträge: 6


Visual Studio 2005
BeitragVerfasst: Do 16.02.06 14:56 
@jasocul,
danke, das ist genau das was ich unter dem Begriff nested IF kenne, also kein ElseIf in C# :( Naja es wird auch ohne gehen :wink: :)

THX
Cisab
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 16.02.06 15:21 
Meinst du sowas?
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
if (x)
  foo1();
else if (y)
  foo2();
else if (z)
  foo3();
else
  foo4();

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Cisab Threadstarter
Hält's aus hier
Beiträge: 6


Visual Studio 2005
BeitragVerfasst: Do 16.02.06 15:27 
Yepp, das is es, hätte also bloss nen Space einfügen müssen :roll: :roll:

THX
Cisab