-2
我試圖擴展'String'類。 到目前爲止,我必須在聲明的字符串對象上創建擴展函數。使用靜態函數擴展字符串類
String s = new String();
s = s.Encrypt();
但我想爲類本身創建一個擴展函數。 在這種情況下,像:String s = String.GetConfig("Test");
我試了一下,到目前爲止:
using System;
using System.Runtime.CompilerServices;
namespace Extensions.String
{
public static class StringExtensions
{
// Error
public string DecryptConfiguration
{
get
{
return "5";
}
}
// Can't find this
public static string GetConfig(string configKey);
// Works, but not what I would like to accomplish
public static string Encrypt(this string thisString);
}
}
任何幫助將不勝感激。 提前謝謝!
你不能做到這一點。 – SLaks
有關擴展函數的詳細信息,請參閱:https://msdn.microsoft.com/en-us/library/bb383977.aspx –