⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample15.cs

📁 C#函数手册
💻 CS
字号:
namespace apibook
{
	using System;

	public class TestParentClass
	{//创建一个空的父类
	}
	public class TestChildClass: TestParentClass 
	{//创建一个继承TestParentClass类的子类
	}
	public class TestObject
	{
		public static void Main() 
		{
			TestParentClass testP = new TestParentClass();
			TestChildClass testC = new TestChildClass();
			object obj = new Object();
			Console.WriteLine("testP.GetType()="+ testP.GetType());
			//使用GetType方法获取当前对象的类型
			Console.WriteLine("testC.GetType()"+ testC.GetType());
			Console.WriteLine("obj.GetType()="+obj.GetType());
			obj=testP;
			Console.WriteLine("执行obj=testP后。。。。");
			Console.WriteLine("obj.GetType()="+ obj.GetType());
			//确定GetType方法是返回当前对象的类型,而不是引用的类型
			A tempA=new A();
			B tempB=new B();
			C c=new C();
			Console.WriteLine("tempA.GetHashCode()="+tempA.GetHashCode());
			Console.WriteLine("tempB.GetHashCode()="+tempB.GetHashCode());
			Console.WriteLine("c.GetHashCode()="+c.GetHashCode());
			int tempI=123456789;
			Console.WriteLine("tempI.ToString()="+tempI.ToString());
		}
		public class A
		{
			public override int GetHashCode()
			{
				return 1;
			}
		}
		public class B
		{
			public override int GetHashCode()
			{
				//重写GetHashCode方法
				return 2;
			}
		}
		public class C
		{
			A a=new A();
			B b=new B();
			public override int GetHashCode()
			{
				//重写GetHashCode方法
				return a.GetHashCode()^b.GetHashCode();
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -