1、new的用法
using System;
using System.Collections.Generic;
using System.Text;
namespace yanz
{
public class student
{
public string strName;
public student(string _strName)
{
this.strName=_strName;
}
}
class Program
{
static void Main(string[] args)
{
student s=new student("张三");
student t=new student("李四");
Console.WriteLine(t.strName);
Console.WriteLine(s.strName);
Console.ReadLine();
}
}
}
Student为类,“student s=new student("张三”);"中“s”代表张三

2、引用参数
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
class myclass
{
public void Swap(ref int x,ref int y)
{
int k;
k=x;
x=y;
y=k;
}
}
class Program
{
static void Main(string[] args)
{
int a=8;b=10;
Console.WriteLine("a={0},b={1}",a,b);
myclass mycl=new myclass();
mycl.Swap(ref a,ref b);
Console.WriteLine("a={0},b={1}",a,b);
}
}
}

3、方法重载
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class student
{
public string strname;
public int nage;
public void grow()
{
this.nage++;
}
public void grow(int _nagespan)
{
this.nage +=_nagespan;
}
}
class Program
{
static void Main(string[] args)
{
student s=new student();
s.strname="zhangsan";
s.nage=20;
s.grow();
Console.WriteLine(s.nage);
s.grow(3);
Console.WriteLine(s.nage);
Console.ReadLine();
}
}
}
4、方法的调用
using System;
using System.Collections.Generic;
using System.Text;
namespace Example_ConstructOverload
{
class Time
{
public int nHour,nMinute,nSecond;
public Time()
{
nHour=nMinute=nSecond=0;
}
public Time(int Hour)
{
nHour=Hour;
nMinute=nSecond=0;
}
public Time(int Hour,int Minute)
{
nHour=Hour;
nMinute=Minute;
nSecond=0;

}
public Time(int hour,int Minute,int Second)
{
nHour=hour;
nMinute=Minute;
nSecond=Second;
}
}
class Test
{
static void Main()
{
Time t1,t2,t3,t4;
t1=new Time();
t2=new Time(10);
t3=new Time(10,20);
t4=new Time(10,22,30);
Console.WriteLine("t1的时间为:{0}时{1}分{2}秒",t1.nHour,t1.nMinute,t1.nSecond);
Console.WriteLine("t2的时间为:{0}时{1}分{2}秒:",t2.nHour,t2.nMinute,t2.nSecond);
Console.WriteLine("t3的时间为:{0}时{1}分{2}秒:",t3.nHour,t3.nMinute,t3.nSecond);
Console.WriteLine("t4的时间为:{0}时{1}分{2}秒:",t4.nHour,t4.nMinute,t4.nSecond);
Console.ReadLine();
}
}
}

最新文章

  1. WCF Security基本概念(转载)
  2. 利用ANTLR4实现一个简单的四则运算计算器
  3. 13 Balls Problem
  4. EF的表连接方法Include()
  5. 第二百二十七天 how can I 坚持
  6. [book]awesome-machine-learning books
  7. 【原创】Linux 增加系统调用
  8. WCF - 实例与会话
  9. WIN7 64位通过VPN远程登录 ASP.Net通过VPN访问Oracle服务器
  10. Frameset使用教程
  11. Hibernate(十二):HQL查询(一)
  12. 使用IIS应用程序初始化来保持ASP.NET应用程序的活动
  13. Android ble蓝牙问题
  14. 反射获取Class对象
  15. 兼容 Spring Boot 1.x 和 2.x 配置类参数绑定的工具类 SpringBootBindUtil
  16. Java 详解 JVM 工作原理和流程
  17. Windows核心编程:第5章 作业
  18. scala中Option和Some
  19. JS DOM节点
  20. iOS菊花加载圈

热门文章

  1. Controlled Tournament(状态压缩DP)
  2. spring jpa data笔记
  3. Oracle 查询每天执行慢的SQL
  4. lua取随机数
  5. static静态变量-投票案例
  6. VMware给虚拟机绑定物理网卡
  7. .Net中的不可变集合(Immutable Collection)简介
  8. 细说JavaScript对象(4): for in 循环
  9. 【XStream】xml和java实体的相互转化
  10. UVa11988 Broken Keyboard(练习链表使用)