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

📄 class1.cs

📁 C#开发教程 由浅入深 配有实例 是初学者的好帮手
💻 CS
字号:
using System;

namespace VarArgs
{
	class Point
	{
		public Point(int x, int y)
		{
			this.x = x;
			this.y = y;
		}

		public int x;
		public int y;
	}

	class Chart
	{
		public void DrawLine(params Point[] p)
		{
			Console.WriteLine("\nThis method would print a line " 
				+ "along the following points:");
			for (int i = 0; i < p.GetLength(0); i++)
			{
				Console.WriteLine("{0}, {1}", p[i].x, p[i].y);
			}
		}
	}

	class OpenEnded
	{
		public void Foo(params object[] pp)
		{
			for (int i = 0; i < pp.GetLength(0); i++)
			{
				Console.WriteLine(pp[i]);
			}
		}
	}

	class TestVarArgs
	{
		[STAThread]
		static void Main(string[] args)
		{
			Point p1 = new Point(5,10);
			Point p2 = new Point(5, 15);
			Point p3 = new Point(5, 20);
	        
			Chart chart = new Chart();
			chart.DrawLine(p1, p2, p3);  
      
			Point[] pts = {		new Point(1,2), 
								new Point(3,4), 
								new Point(5,6)	};
			chart.DrawLine(pts);

			OpenEnded oe = new OpenEnded();
			oe.Foo(123, 456, "Hello", new Point(7,8), 
				9.0m, true, 'X');
		}
	}
}

⌨️ 快捷键说明

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