[C#][VB.NET]擴充方法 (Extension Method)
public static class EnumExtension
{
public static string GetName(this Enum e)
{
return Enum.GetName(e.GetType(), e);
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Grade.APlus.GetName());
}
}</pre></div>
Enum Grade APlus A B C D End Enum
Module Module1 Sub Main() Console.WriteLine(Grade.APlus.GetName) End Sub End Module
Module EnumExtension <Extension()> _ Public Function GetName(ByVal e As [Enum]) As String Return [Enum].GetName(e.GetType, e) End Function End Module
class Program
{
static void Main(string[] args)
{
string str = null;
Console.WriteLine(str.IsNull().ToString());
}
}</pre></div>
Module Module1
Sub Main()
Dim str As String = Nothing
Console.WriteLine(str.IsNull().ToString())
End Sub
End Module
Module StringExtension <Extension()> _ Public Function IsNull(ByVal str As String) As Boolean Return str Is Nothing End Function End Module