class1.cs

来自「C#开发教程 由浅入深 配有实例 是初学者的好帮手」· CS 代码 · 共 50 行

CS
50
字号
using System;

namespace WindowByRef
{
	class Window
	{
		public Window(int x, int y)
		{
			this.x = x;
			this.y = y;
		}

		protected int x;
		protected int y;

		public void Move(int x, int y)
		{
			this.x = x;
			this.y = y;
		}

		public void ChangePos(ref int x, ref int y)
		{
			this.x += x;;
			this.y += y;

			x = this.x;
			y = this.y;
		}
	}

	class TestWindowByRef
	{
		public static void Main()
		{
			Window wnd = new Window(5, 5);
			int x = 5;
			int y = 5;

			wnd.ChangePos(ref x, ref y);
			Console.WriteLine("{0}, {1}", x, y);

			x = -1;
			y = -1;
			wnd.ChangePos(ref x, ref y);
			Console.WriteLine("{0}, {1}", x, y);
		}
	}
}

⌨️ 快捷键说明

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