Vb转换为c#转换混乱 - directCast和MyBase.Item

时间:2017-04-05 10:02:56

标签: c# asp.net vb.net type-conversion

将vb转换为c#,这是

的c#中最好的等价物
<ConfigurationProperty("name", IsKey:=True, IsRequired:=True)> _
        Public Property Name() As String
            Get
                Return DirectCast(MyBase.Item("name"), String)
            End Get
            Set(ByVal value As String)
                MyBase.Item("name") = value
            End Set
        End Property

1 个答案:

答案 0 :(得分:1)

它的返回类型字符串,只需将其转换为字符串。尝试以下代码。

[ConfigurationProperty("name", IsKey = true, IsRequired = true)]
public string Name 
{
  get { return (string)base["name"]; }
  set { base["name"] = value; }
}