Can you help me C# switch case -
i have code c# switch case
public void gdvdetail_customunboundcolumndata(object sender, devexpress.xtragrid.views.base.customcolumndataeventargs e) { try { datarowview orow = (datarowview)(gdvdetail.getrow(e.listsourcerowindex)); switch (e.column.name) { case colquotaquantity.name: if (colquotaquantity.unboundexpression == "" && orow.row.table.columns.contains("quotaquantity")) { e.value = orow.row["quotaquantity"]; } break; //e.value = orow.row("quantity") case coldifferencequantity.name: if (orow.row.table.columns.contains("quotaquantity") && !information.isdbnull(orow.row["quotaquantity"]) && !information.isdbnull(orow.row["quantity"])) { e.value = system.convert.todouble(orow.row["quantity"]) - system.convert.todouble(orow.row["quotaquantity"]); } break; } } catch (exception ex) { commonfunction.showexclamation(ex.message); } }
when try compile application, receive following errors:
a constant value expected
line : case colquotaquantity.name:
line : case coldifferencequantity.name:
can me?
the values in switch/case
statement have compile-time constants, numeric values or string literals:
switch(i) { case 0: /*...*/ break; case 1: /*...*/ break; } switch(s) { case "hello": /*...*/ break; case "world": /*...*/ break; }
you cannot use variables value known @ run-time, not @ compile time. case coldifferencequantity.name:
not valid in c#.
you convert code if
statements:
if (e.column.name == colquotaquantity.name) { /* ... */ } else if (e.column.name == coldifferencequantity.name)
Comments
Post a Comment