如何解决我需要什么版本的 system.dll 才能在 c# 上启用 get{} 和 set{} 属性?
嗨,我是一名软件程序员和硬件设计师。我在使用 C# 语言的 VISUAL BASIC 软件时遇到问题。每当我输入 get{} / set{} 参数时,错误接口都会检测到错误。它说“名称“get”在上下文中不可用。我不知道要解决什么问题,因为我只在彻底应用 C++ 技能时才学习了 C#。我在 Microsoft 上打开了许多 DLL,但没有解决任何问题。1) 是吗需要新的库吗?2) 我在哪里可以下载和安装 C# 的 get/set 命令的 DLL(在安全模式下)?
解决方法
每当我输入 get{} / set{} 参数时,错误接口都会检测到错误。它说“名称“get”在上下文中不可用
get
和 set
关键字在 C# 中的 property 或 indexer 定义的上下文中被识别:
class MyType
{
private string _myString;
public string MyStringProperty
{
// this is a property definition,`get` and `set` are recognized in this context
get { return _myString; }
set { _myString = value; }
}
public char this[int i]
{
// this is an indexer definition,`get` and `set` are also recognized in this context
get { return i >= 0 && i < _myString.Length ? _myString[i] : '\0'; }
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。