• 类型之间进行隐式和显示转换&创建使用枚举&创建使用结构类型&创建使用数组&;如何处理字符串值


    C#入门经典第五版.pdf---第五章

    隐式转换可以直接转换,显示转换需要采取一些手段:类型1 = (类型1的类型)类型2;

    checked和unchecked进行表达式的溢出检查上下文。类型2 = checked((类型1的类型)类型2);若溢出会报错。使用unchecked不会检查。

    使用Convert进行显示转换

                                                      遍历输出数组信息:

    foreach( double  height in hillHeight)

    {

          console.writeLine("{0}",height);

    }

                      接口的实现:

    定义一个接口:interface IMYInterface

    {

           //Interface  members.

    }

    接口成员的定义与类成员的定义相似,但有几个重要的区别:

    不允许使用访问修饰符(public、private、protected或internal),所有的接口成员都是公共的。

    接口成员不能包含代码体。

    接口不能定义字段成员。

    接口成员不能用关键字static、virtual、abstract或sealed来定义。

    类型定义成员是禁止的。

    隐藏继承了基接口的成员,可以使用关键字new来定义它们:

    interface IMyBaseInterface

    {

        void DoSomething();

    }

     interface IMyDeriveInterface : IMyBaseInterface

    {

        new void DoSomething();

    }

    其执行方式与隐藏继承的类成员的方式一样。

    在接口中定义的属性可以定义访问块get和set中的哪一个能用于该属性:

    interface IMyInterface

    {

        int MyInt{get ;set:};

    }

    在类中实现接口

    public interface IMyInterface

    {

         void DoSomething();

         void DoSomethingElse();

    }

    public class MyClass : IMyInterface

    {

      public void DoSomething()

        {}

      public void DoSomethingElse()

        {}

    }

    可以使用关键字virtual或abstract来实现接口成员,但不能使用static或const。还可以在基类上实现接口成员:

    public interface IMyInterface

    {

        void DoSomething();

        void DoSomethingElse();

    }

    public class MyBaseClass

    {

      public void DoSomething()

        {}

    }

    public class MyDeriveClass :MyBaseClass,IMyInterface

    {

      public void DoSomethingElse()

        {}

    }

    继承一个实现给定接口的基类,就意味着派生类隐式地支持这个接口:

    public interface IMyInterface

    {

      void DoSomething();

         void DoSomethingElse();

    }

    public class MyBaseClass : IMyInterface

    {

        public virtual void DoSomething()

        {}

        public virtual void DoSomethingElse()

        {}

    }

    public class MyDerivedClass : MyBaseClass

    {

      public override void DoSomething()

      {}

    }

  • 相关阅读:
    死锁:同步中嵌套同步,但锁不同,示例二:
    WinCC VBS利用EXCEL调用Windows API函数
    IE8在上传文件时路径无效或无效的图片文件解决办法【转】
    jquery 资料
    设置倒计时10秒可用的按钮JS函数(转)
    WINCC中数据EXCEL报表的实现方法
    Js 操作radiobuttonlist的方法 (转)
    转自百度 silverlight(转)
    Silverlight五子棋(转)
    两台Oracle服务器,使用udl测试连接
  • 原文地址:https://www.cnblogs.com/quwujin/p/5442601.html
Copyright © 2020-2023  润新知