c#基础之数组与接口使用示例(遍历数组 二维数组)
发布时间:2020-12-15 05:50:47 所属栏目:百科 来源:网络整理
导读:一、初始化数组: 复制代码 代码如下: string[] s1 = {“aaa”,”bbb”,”ccc”} //直接赋值 string[] s2 = new string[5] {“aaa”,”ccc”}; //赋值加指定长度 string[] s3 = new string[]{“aaa”,”ccc”}; string[] s4 = new string[5]; //用循环直接赋
一、初始化数组: 复制代码 代码如下: string[] s1 = {“aaa”,”bbb”,”ccc”} //直接赋值 string[] s2 = new string[5] {“aaa”,”ccc”}; //赋值加指定长度 string[] s3 = new string[]{“aaa”,”ccc”}; string[] s4 = new string[5]; //用循环直接赋值 二、遍历数组: 复制代码 代码如下: foreach (string s in str) { Console.Write(s); } 三、二维数组: 五、接口 使用new修饰符可以隐藏继承自基类的接口 复制代码 代码如下: public class Class2:Class1 { new public interface Iinterface { void Print(); } } 继承多个接口: 复制代码 代码如下: public interface Iinterface3 : Iinterface1,Iinterface2,Iinterface3 { void Print3(); } 接口的属性方法等不能具体实现,只能声明。如: 复制代码 代码如下: public interface Iinterface { string Name { get; set; } } 实现接口: 抽象类和接口的区别: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |