Mega Code Archive

 
Categories / C# / Data Types
 

Any object, value, or reference type that is convertible to an integral, char, enum, or string type is acceptable as the switch

using System; class Employee {     public Employee(string f_Emplid) {         m_Emplid = f_Emplid;     }     static public implicit operator string(Employee f_this) {         return f_this.m_Emplid;     }     private string m_Emplid; } class Starter {     static void Main() {         Employee newempl = new Employee("1234");         switch (newempl) {             case "1234":                 Console.WriteLine("Employee 1234");                 return;             case "5678":                 Console.WriteLine("Employee 5678");                 return;             default:                 Console.WriteLine("Invalid employee");                 return;         }     } }