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

📄 2.2.txt

📁 《Microsoft Visual C# .NET 2003开发技巧大全》源代码
💻 TXT
字号:
Listing 2.2 Reflecting Parameter Changes by Using the ref Modifier
namespace _3_Methods
{
public class Television
{
// current channel tv is set to
private static int channel = 2;
private const int maxChannels = 200;
// changes the channel to a specified channel
public bool ChangeChannel(int newChannel)
{
// only supports 200 channels
if( newChannel > maxChannels )
return false;
// set private channel variable
channel = newChannel;
return true;
}
public void GetChannel( int param )
{
param = channel;
}
// overloaded version. Note ref parameter
public void GetChannel( ref int param )
{
param = channel;
}
}
class Class1
{
[STAThread]
static void Main(string[] args)
{
// create Television object
Television tv = new Television();
int refChan = 0;
int chan = 0;
// chan remains 0 after call
tv.GetChannel( chan );
// refChan’s value will change
tv.GetChannel( ref refChan );
Console.WriteLine( “noref={0} ref={1}”, chan, refChan );
}
}
}

⌨️ 快捷键说明

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