设为首页 加入收藏

TOP

类型和变量(C#学习笔记02)(二)
2019-10-10 11:17:36 】 浏览:351
Tags:类型 变量 学习 笔记
nbsp;的用户定义类型
接口只包含方法、属性、事件或索引器的签名。 实现接口的类或结构必须实现接口定义中指定的接口成员。
实例:

interface ISampleInterface       //只定义声明
{
    void SampleMethod();
}

class ImplementationClass : ISampleInterface
{
    // Explicit interface member implementation: (具体的方法实现在类中实现)
    void ISampleInterface.SampleMethod()
    {
        // Method implementation.(方法代码)
    }

    static void Main()
    {
        // Declare an interface instance.
        ISampleInterface obj = new ImplementationClass();

        // Call the member.
        obj.SampleMethod();
    }
}

3. 数组类型

一维和多维,例如 int[] 和 int[,]
可以将同一类型的多个变量存储在一个数组数据结构中。 通过指定数组的元素类型来声明数组。

class TestArraysClass
{
    static void Main()
    {
        // Declare a single-dimensional array. 
        int[] array1 = new int[5];

        // Declare and set array element values.
        int[] array2 = new int[] { 1, 3, 5, 7, 9 };

        // Alternative syntax.
        int[] array3 = { 1, 2, 3, 4, 5, 6 };

        // Declare a two dimensional array.
        int[,] multiDimensionalArray1 = new int[2, 3];

        // Declare and set array element values.
        int[,] multiDimensionalArray2 = { { 1, 2, 3 }, { 4, 5, 6 } };

        // Declare a jagged array.
        int[][] jaggedArray = new int[6][];

        // Set the values of the first array in the jagged array structure.
        jaggedArray[0] = new int[4] { 1, 2, 3, 4 };
    }
}

4. 委托类型

格式为 delegate int D(...) 的用户定义类型
具体参考:事件与委托学习笔记03

https://www.cnblogs.com/asahiLikka/p/11644393.html

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C#事件和委托(C#学习笔记03) 下一篇dotnetcore+vue+elementUI 前后端..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目