C# Common Keyword II

1、as 运算符用于在兼容的引用类型之间执行某些类型的转换。

   class csrefKeywordsOperators
   {
       class Base
       {
           public override string  ToString()
           {
                 return "Base";
           }
       }
       class Derived : Base 
       { }

       class Program
       {
           static void Main()
           {

               Derived d = new Derived();

               Base b = d as Base;
               if (b != null)
               {
                   Console.WriteLine(b.ToString());
               }

           }
       }
   }
View Code

相关文章:

  • 2021-07-16
  • 2022-02-27
  • 2021-06-12
  • 2021-09-23
  • 2022-01-09
  • 2021-09-21
猜你喜欢
  • 2022-02-13
  • 2021-08-04
  • 2021-09-25
  • 2022-02-03
  • 2022-12-23
  • 2021-09-06
  • 2022-01-11
相关资源
相似解决方案