2013-09-27 33 views
0

以下是密封类。我如何访问该类中的方法?如何访问密封类中的静态字符串

Public NotInheritable Class ConnectionStringProvider 
    Public Shared Function GetConnectionString() As String 
     Dim tReturn As String = "" 
     Try 
      tReturn = _ConnectionString 
     Catch 
     Finally 
     End Try 
     Return tReturn 
    End Function 
End Class 

在此先感谢

+0

您无法继承静态/共享成员,那么sealed/NotInheritable会与它有什么关系? – Jodrell

回答

1

只需使用类名和函数名:

Dim ConString As String = ConnectionStringProvider.GetConnectionString() 

如果不能满足您的查询的话,请详细说明你的问题。

+0

代码会更好,因为Dim conString = ConnectionStringProvider.GetConnectionString()IMO。 – Jodrell

0

您可以访问它。我不认为这有问题。

这是我用一个例子做的。

sealed class Example 
{ 
    public static void GetStringValue() 
    { 
     Console.WriteLine("Inside Example"); 
    } 
} 

,并与类即名下它,在这​​种情况下,例

所以:

Example.GetStringValue()将产生我

里面例

这是你想说什么?