要为变量分配引用,请使用 ref 关键字。引用参数是指向变量内存位置的引用。当你通过引用传递参数时,与值参数不同,不会为这些参数创建新的存储位置。使用 ref 关键字声明引用参数。让我们来看一个例子:在这里,我们使用 ref 关键字交换两个值:示例 在线演示using System; namespace Demo { class Program { public void swap(ref int x, ref int y) { int temp; temp = ... 阅读更多
按位左移运算符左操作数的值向左移动由右操作数指定的位数。按位右移运算符左操作数的值向右移动由右操作数指定的位数。以下是一个演示如何使用按位左移和右移运算符的示例:示例 在线演示using System; namespace Demo { class Program { static void Main(string[] args) { int a = 60; /* 60 = 0011 1100 */ int b = 13; /* 13 = 0000 1101 */ int c = 0; c = a >> 2; /* 15 = 0000 1111 */ Console.WriteLine("Value of c is {0}", c); Console.ReadLine(); } } }输出Value of c is 15 Value of c is 240