1
這顯示http://msdn.microsoft.com/en-us/library/bb311042.aspx可以跳過對公共靜態名稱空間中的公共靜態擴展類的引用。 但是,它不適用於公共靜態變量。c#允許跳過只對擴展方法的靜態類的引用嗎?
using UnityEngine;
using System.Collections;
namespace NDefault
{
public static class TDefault
{
public static int CNT=71;
public static bool has_method(this object target,string method_name)
{
return target.GetType().GetMethod(method_name)!=null;
}
}
}
_
using UnityEngine;
using System.Collections;
using NDefault;
public class TController :MonoBehaviour
{
void Start()
{
int t;
print (t.has_method("GetType")); //This prints "True"
print (CNT);//This creates error "The name `CNT' does not exist in the current context"
}
void Update()
{
}
}
我說得對不對,對於使用靜態變量和方法沒有一個類的引用,我要繼承非靜態默認類包含它們的所有類,而對於延期方法我應該在命名空間中創建一個單獨的靜態類?即我無法將它們存儲在一起?