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

    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()

      {}

    }

  • 相关阅读:
    HTML5 & CSS3编程入门经典 ((美)Rob Larsen) pdf扫描版
    HTML5+JavaScript动画基础 完整版 中文pdf扫描版
    HTML5程序开发范例宝典 完整版 (韩旭等著) 中文pdf扫描版
    HTML5从入门到精通(明日科技) 中文pdf扫描版
    HTML5秘籍(第2版) 中文pdf扫描版
    HTML5与CSS3实例教程(第2版) 附源码 中文pdf扫描版
    windows下一分钟配置ngnix实现HLS m3u8点播
    linux下搭建生成HLS所需的.ts和.m3u8文件
    使用Flash Media Server(FMS)录制mp4格式的视频
    FMS 客户端带宽计算、带宽限制
  • 原文地址:https://www.cnblogs.com/quwujin/p/5442601.html
Copyright © 2011-2022 走看看