Skip to main content
Rollback to Revision 1
Source Link
Cyber Oliveira
  • 8.7k
  • 4
  • 31
  • 19

One lesser-known known facet of switch in C# is that it relies on the operator=, and since it can be overridden,overriden you could have something like this:

string s = foo();

switch (s) {
  case "abc": /*...*/ break;
  case "def": /*...*/ break;
}

string s = foo();

switch (s) {
  case "abc": /*...*/ break;
  case "def": /*...*/ break;
}

One lesser-known facet of switch in C# is that it relies on the operator=, and since it can be overridden, you could have something like this:

string s = foo();

switch (s) {
  case "abc": /*...*/ break;
  case "def": /*...*/ break;
}

One lesser known facet of switch in C# is that it relies on the operator= and since it can be overriden you could have something like this:


string s = foo();

switch (s) {
  case "abc": /*...*/ break;
  case "def": /*...*/ break;
}
Minor improvements.
Source Link
Pang
  • 10.2k
  • 146
  • 87
  • 126

One lesser known-known facet of switch in C# is that it relies on the operator=, and since it can be overridenoverridden, you could have something like this:


string s = foo();

switch (s) {
  case "abc": /*...*/ break;
  case "def": /*...*/ break;
}
string s = foo();

switch (s) {
  case "abc": /*...*/ break;
  case "def": /*...*/ break;
}

One lesser known facet of switch in C# is that it relies on the operator= and since it can be overriden you could have something like this:


string s = foo();

switch (s) {
  case "abc": /*...*/ break;
  case "def": /*...*/ break;
}

One lesser-known facet of switch in C# is that it relies on the operator=, and since it can be overridden, you could have something like this:

string s = foo();

switch (s) {
  case "abc": /*...*/ break;
  case "def": /*...*/ break;
}
Source Link
Cyber Oliveira
  • 8.7k
  • 4
  • 31
  • 19

One lesser known facet of switch in C# is that it relies on the operator= and since it can be overriden you could have something like this:


string s = foo();

switch (s) {
  case "abc": /*...*/ break;
  case "def": /*...*/ break;
}