C#中的class和interface

编程入门 行业动态 更新时间:2024-10-11 19:18:04

C#中的<a href=https://www.elefans.com/category/jswz/34/1769088.html style=class和interface"/>

C#中的class和interface

C#中的class
namespace Class和interface
{class Program{static void Main(string[] args){Person person = new Person();Console.WriteLine(person.GetAge(1));//调用时使用实例化的对象调用Console.WriteLine(Person.GetFive());//static方法使用时直接使用"类名.方法"调用,不能使用实例化后的对象调用//静态的方法或字段是存储在class类上的,不能实例化}}class Person{   //可以包含字段、方法、属性int age;public int GetAge(int Mage){this.age=Mage;//this表示当前class实例化后的对象,因为在自己的class中可以省略this不写return age;}public static int GetFive(){return 5;}}
}
C#类中的属性
public int Age {get //get从旧内存中取值{return age + 10;}

更多推荐

C#中的class和interface

本文发布于:2024-02-06 12:02:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1749055.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:class   interface

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!