using System;
using System.Collections;namespace BioCareControls
{
/// <summary>
/// A wrapper around a Hashtable for configuration items. Configuration items are intended to be used by the property Grid
/// </summary>
public class Settings
{
private Hashtable settings;
public Settings()
{
settings = new Hashtable();
} /// <summary>
/// Get the key collection for this Settings object. Every key is a string
/// </summary>
public ICollection Keys
{
get{return settings.Keys;}
} /// <summary>
/// Get/Set the Setting object tied to the input string
/// </summary>
public SettingParameter this[string key]
{
get
{
return (SettingParameter)settings[key];
}
set
{
settings[key]=value;
value.Name=key;
}
} /// <summary>
/// Gets the Setting object tied to the string. If there is no Setting object, one will be created with the defaultValue
/// </summary>
/// <param name="key">The name of the setting object</param>
/// <param name="defaultvalue">if there is no Setting object tied to the string, a Setting will be created with this as its Value</param>
/// <returns>The Setting object tied to the string</returns>
public SettingParameter GetSetting(string key, object defaultvalue)
{
if(settings[key]==null)
{
settings[key] = new SettingParameter(defaultvalue, null, null);
((SettingParameter)settings[key]).Name = key;
}
return (SettingParameter)settings[key];
}
}
}请问一下,红色字体标注的方法是什么写法?this[string key] 代表什么? 其中SettingParameter是一个类,定义了显示在CustomPropertyGrid上面的信息。
using System.Collections;namespace BioCareControls
{
/// <summary>
/// A wrapper around a Hashtable for configuration items. Configuration items are intended to be used by the property Grid
/// </summary>
public class Settings
{
private Hashtable settings;
public Settings()
{
settings = new Hashtable();
} /// <summary>
/// Get the key collection for this Settings object. Every key is a string
/// </summary>
public ICollection Keys
{
get{return settings.Keys;}
} /// <summary>
/// Get/Set the Setting object tied to the input string
/// </summary>
public SettingParameter this[string key]
{
get
{
return (SettingParameter)settings[key];
}
set
{
settings[key]=value;
value.Name=key;
}
} /// <summary>
/// Gets the Setting object tied to the string. If there is no Setting object, one will be created with the defaultValue
/// </summary>
/// <param name="key">The name of the setting object</param>
/// <param name="defaultvalue">if there is no Setting object tied to the string, a Setting will be created with this as its Value</param>
/// <returns>The Setting object tied to the string</returns>
public SettingParameter GetSetting(string key, object defaultvalue)
{
if(settings[key]==null)
{
settings[key] = new SettingParameter(defaultvalue, null, null);
((SettingParameter)settings[key]).Name = key;
}
return (SettingParameter)settings[key];
}
}
}请问一下,红色字体标注的方法是什么写法?this[string key] 代表什么? 其中SettingParameter是一个类,定义了显示在CustomPropertyGrid上面的信息。
解决方案 »
- 请各位大侠帮我解释一下:SocketAsyncEventArgsPool
- 100分求CCF精品论坛的账号
- SQL Server 不存在或访问被拒绝的问题
- WinForm不需要join就可以实现从数据库中多表连接取数据吗?
- VS2005中如何实现异构数组的属性
- 类的继承问题,立即接贴!简单....
- 接口与继承的区别
- 急!100分求解高难问题:MDI开发,在线程中引用了WebService得到DataSet后赋值给DataGrid,出错!
- 我想开发一个基于.NET的网络纸牌游戏,请高手指点一下!!
- C#:新增数据保存成功更新另一窗口dategridview显示
- 动态按钮的颜色问题
- string的引用传递、值传递的问题
String a = “123”;
a[1]....上面是用一个hash来存储SettingParameter,传一个key进去就能获得相应的SettingParameter值。
this[string key]就当它是一个属性好了。
在其他地方可以将 this["value1"]作为一个对象使用.给它赋值,或者把它的值给别的对象。