Any object, value, or reference type that is convertible to an integral, char, enum, or string type is acceptable as the switch_expression : cast : Data Types C# Source Code


Custom Search

C# Source Code » Data Types » cast »

 

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








    
 

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;
        }
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Data Types
» cast