📄 2.6.txt
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -