Check syntax

  • Thread starter Thread starter Ruslan Shlain
  • Start date Start date
R

Ruslan Shlain

Whats wrong with this code?

public void CleanData(DataSet DS)

{

switch (DS.Tables[0].TableName.ToString())

{

case "scs_ds_vehicle_inventory" :


case "scs_ds_sold_customer" :

case "scs_ds_employee" :

case "scs_ds_fi_deals" :

case "scs_ds_ro_customer" :

case "scs_ds_ro_history" :

DS.Tables["scs_ds_ro_history"].Columns.Remove("m20");

case "scs_ds_ro_vehicle_history" :

DS.Tables["scs_ds_ro_vehicle_history"].Columns.Remove("m20");

}

}
 
Ruslan Shlain said:
Whats wrong with this code?

You're missing break statements. You aren't allowed to fall through
(except through empty cases statements) in C#.

<snip>
 
Marco Martin said:
you need to have a case default

No you don't. For instance:

using System;

class Test
{

static void Main()
{
int i=3;

switch (i)
{
case 0:
Console.WriteLine ("i was 0");
break;
}
}
}

compiles fine.
 
Which kind of makes break statements redundant (I mean, if you cannot fall
through, what is the purpose of the break?)...

Alek
 
Thanks Ed,

I expected the explanation to be the same, but I cannot agree with the
rationale behind it, i.e. making it obvious for C/C++ programmers. Since I
was coming from C/C++ background (7+ years), I assumed that switches in C#
allowed fall-through (since I knew that there were break statements).
Thinking logically, I thought that if you had a break statement, there must
have been an option to fall through. Although, after the first compiler
error, I figured out that my assumption was wrong, so if there are C/C++
programmers who were supposed to benefit from the redundancy, I am not one
of them. In my mind, it is a miss (not the best design decision) and for
every argument for it, I can probably give an argument against. Not a reason
to start religious war, though. There are many issues which are more
serious. ;-)

Alek

Ed Courtenay said:
Have a look at
http://groups.google.co.uk/[email protected]&rnum=1
(watch for line wrapping) for an explanation
 
Back
Top