Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. switch enhancement in C#

switch enhancement in C#

Scheduled Pinned Locked Moved C#
questioncsharpc++javadelphi
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    ovarlamov
    wrote on last edited by
    #1

    What could be done in C# which would add much in language expressiveness without any penalties to security and efficiency. Before implement any language feature I think designers discussed them many times and surely they analyzed any similar implementation in all the languages (not only C,C++, but Java, FoxPro, Pascal, ADA, etc). So C# is not just a revamped dialect version of C++ + garbage collection (such attempts to create garbage collection feature to C++ have been made many times), that's why my question is purely ritoric: why they didn't do that? What is that ... read below. In language description we read that in order to go out of innermost cycle we should use goto operator. Yes, of course, but wouldn't it be better to write something like this? for (condition_1) { .... while(condition_2) { .... break level; // level see next comment /* level - int expression, if 0 means regular break; 1 - means one level up, in this particular case means exit from for cycle */ ... continue level; // see comments above } ... } I've been wondering why it hadn't been done since the first C-compilers appeared, I worked then on PDP11. Java made it better, but still it is too similar to goto.. Another question: Look at this snippet of code if(codition_1) { ....//do smth } else { if(codition_2) { ....//do smth } else { if(codition_3) { ....//do smth } else { } } } isn't it ugly? Imagine 20 conditions analyzed, what will happen to nesting level? Then compare to this: (borrowed from FoxPro,Clipper...) switch { case (condition_1) .... // no need of break, that has become obligatory in C# !!! case (condition_1) ... default: } By the way switch operator in old C-style definition could be used as well, they wouldn't int

    A 1 Reply Last reply
    0
    • O ovarlamov

      What could be done in C# which would add much in language expressiveness without any penalties to security and efficiency. Before implement any language feature I think designers discussed them many times and surely they analyzed any similar implementation in all the languages (not only C,C++, but Java, FoxPro, Pascal, ADA, etc). So C# is not just a revamped dialect version of C++ + garbage collection (such attempts to create garbage collection feature to C++ have been made many times), that's why my question is purely ritoric: why they didn't do that? What is that ... read below. In language description we read that in order to go out of innermost cycle we should use goto operator. Yes, of course, but wouldn't it be better to write something like this? for (condition_1) { .... while(condition_2) { .... break level; // level see next comment /* level - int expression, if 0 means regular break; 1 - means one level up, in this particular case means exit from for cycle */ ... continue level; // see comments above } ... } I've been wondering why it hadn't been done since the first C-compilers appeared, I worked then on PDP11. Java made it better, but still it is too similar to goto.. Another question: Look at this snippet of code if(codition_1) { ....//do smth } else { if(codition_2) { ....//do smth } else { if(codition_3) { ....//do smth } else { } } } isn't it ugly? Imagine 20 conditions analyzed, what will happen to nesting level? Then compare to this: (borrowed from FoxPro,Clipper...) switch { case (condition_1) .... // no need of break, that has become obligatory in C# !!! case (condition_1) ... default: } By the way switch operator in old C-style definition could be used as well, they wouldn't int

      A Offline
      A Offline
      Andy Smith
      wrote on last edited by
      #2

      I agree with you that C# switch statement is unneccesarily poor. It is such things that make me almost want to move to VB.Net. VB and C# are on the same level, performance-wise, and VB has some _great_ syntax niceties such as a GOOD switch statement ( Select/Case ) and the With statement. Although, in the long run I doubt i'll ever switch to vb.net... if only for the reason that I fully expect that a programmer who has "c#" on his resume can demand a higher pay than one with "VB.net" on it; regardless if that is an intelligent decision.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups