2.6.txt
来自「《Microsoft Visual C# .NET 2003开发技巧大全》源代码」· 文本 代码 · 共 28 行
TXT
28 行
Listing 2.6 Defining Properties to Provide Validating Member Variable Access Using
Data-Hiding Techniques
using System;
namespace _6_Properties
{
public class Television
{
private int channel = 1;
// this tv only has 255 channels
private const int maxChannels = 255;
// changes the channel on the tv
public int Channel
{
get
{
return channel;
}
set
{
// check value’s range
if( value > maxChannels )
return;
// set private variable
channel = value;
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?