public int add(int a, int b)
{
return a+b;
}
<span style="font-size:18px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Text
{
class A
{
int exaVar;//创建的一个为实例成员变量
static int stVar;//创建的一个静态成员变量
void tM()//实例方法
{
exaVar = 1;//等价于this.exVar=1
stVar = 1;//等价于A.stVar=1
}
static void sM()//静态方法
{
//exaVar = 1;//错误,静态方法不可以调用实例成员变量
stVar = 1;//等价于A.stVar=1
}
static void Main(string[] args)
{
A text = new A();//创建类A的对象为text
text.exaVar = 1;//对象text访问实例成员变量
A.stVar = 1;//只能使用类访问静态成员变量
//text.stVar = 1;//不能使用对象text访问静态成员变量
text.tM();//使用对象text访问实例成员方法
//text.sM();//不能使用对象text访问静态成员方法
A.sM();//使用类访问静态成员方法
Console.WriteLine(text.exaVar + A.stVar);
Console.ReadLine();
}
}
}</span>
<span style="font-size:18px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Text
{
public class A
{
public virtual void ab()//定义的类A的虚方法 </span>
[csharp] view plaincopyprint?
<span style="font-size:18px;"> {
Console.WriteLine("这是虚方法");
}
public void ac()//定义的类A的非虚方法
{
Console.WriteLine("这是非虚方法");
}
}
public class B:A//类B私有继承类A
{
public override void ab()//重写继承的ab方法
</span> <span style="font-size:18px;"> {
Console.WriteLine("这是新的方法");
}
public new void ac()//创建一个新的方法覆盖原来的ac方法
{
Console.WriteLine("这是另一个新的方法");
}
}
class Program
{
static void Main(string[] args)
{
B b = new B();//创建类B的对象b
A a = b;//将对象b赋值给类A的对象a
a.ab();//调用原ab虚方法
b.ab();//调用ab方法
a.ac();//调用原ac非虚方法
b.ac();//调用ac方法
Console.ReadLine();
}
}
}</span>
<span style="font-size:18px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Text
{
class A
{
public virtual void a()//创建的虚方法
{
Console.WriteLine("这是虚方法");
}
}
class B : A
{
public override void a()
{
Console.WriteLine("这是重写后的方法");
</span> }
}
<span style="font-size:18px;">class Program
{
static void Main(string[] args)
{
B b1 = new B();//创建类B的对象b1
b1.a();//调用重写后的a方法
A a1 = new A();//创建类A的对象a1
a1.a();//调用虚方法a
A a2 = b1;//将类B的对象b1赋值给类A的对象a2
a2.a();//调用虚方法a
Console.ReadLine();
}
}
}
</span>
<span style="font-size:18px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;//必须引入的命名空间
namespace Text
{
class Program
{
[DllImport("User32.dll")]//调用User32.dll
public static extern int MessageBox(int H, string m, string c, int type);//定义的外部方法
static int Main(string[] args)
{
Console.Write("请输入信息:");
string str = Console.ReadLine();//接受输入的信息
return MessageBox(0,str,"我的信息提示框",0);//以信息提示框输出
}
}
}</span>
<span style="font-size:18px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Text
{
public partial class Program//定义的分部类
{
private int _setup;//定义的字段
public int setup//定义的方法
{
set
{
_setup=value;
}
get
{
return _setup;
}
}
partial void text(int t);//声明分部方法
partial void text(int t)//实现声明
{
t += _setup;
Console.Write(t);
}
}
partial class Program
{
static void Main(string[] args)
{
Program pg = new Program();//创建类对象
pg._setup = 100;//设置属性
pg.text(50);//调用方法
Console.ReadLine();
}
}
}</span>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有