Fall through i Switch sats

.NET

3 svar · 222 visningar · startad av Viktor

Medlem sedan aug. 20021 752 inlägg
Trådstart#1

Jag vill ha en switch sats som ser ut såhär

switch(xmlIterator.Current.Name)
{
	case "name":
		Console.WriteLine("Name: "+xmlIterator.Current.Value);
		break;
	case "info":
		Console.WriteLine("Info: "+xmlIterator.Current.Value);
		break;
	case "pointinfo":
		xmlIterator.Current.MoveToFirstChild();
	case "pointpos":
		xmlIterator.Current.MoveToFirstAttribute();
		Console.Write("Pos: {0}",xmlIterator.Current.Value);
		xmlIterator.Current.MoveToNextAttribute();
		Console.WriteLine(", Points: {0}",xmlIterator.Current.Value);
		break;
};

dvs när den kommer ner till "pointinfo" så ska den göra det som står där och sedan gå vidare och göra det som står under "pointpos", men när jag försöker göra det så får jag

Controll cant fall through one case lable to another.

Finns det något sätt att göra så det går?

/Viktor

Medlem sedan sep. 20011 914 inlägg
#2

Re: Fall through i Switch sats

Kanske så här?

bool grr;
switch(xmlIterator.Current.Name)
{
	case "name":
		Console.WriteLine("Name: "+xmlIterator.Current.Value);
		break;
	case "info":
		Console.WriteLine("Info: "+xmlIterator.Current.Value);
		break;
	case "pointinfo":
		xmlIterator.Current.MoveToFirstChild();
                                grr = true;
                                break;
	case "pointpos":
		xmlIterator.Current.MoveToFirstAttribute();
		Console.Write("Pos: {0}",xmlIterator.Current.Value);
		xmlIterator.Current.MoveToNextAttribute();
		Console.WriteLine(", Points: {0}",xmlIterator.Current.Value);
		break;
};
if(grr == true){
   //do stuff
   grr = false
}
Medlem sedan maj 2001329 inlägg
Medlem sedan aug. 20021 752 inlägg
#4

Tack, det var något sånt som jag ville ha.

/Viktor

403 ms totalt · 4 externa anrop · v20260731065814-full.d34c6d5a
123 ms — deklarationer (db)
151 ms — hämta statistik (db)
126 ms — hämta tråd, inlägg och bilagor (db)
122 ms — ändringar (db)