2014-01-17 36 views
0

我收到以下錯誤對象引用需要非靜態字段,方法或屬性在GetAbbreviatedMonthName

An object reference is required for the non-static field, method, or 
property 'System.Globalization.DateTimeFormatInfo.GetAbbreviatedMonthName(int). 

雖然我嘗試添加月份縮寫名稱的字符串列表類似如下。

List<string> monList = new List<string>(); 
monList.Add(System.Globalization.DateTimeFormatInfo.GetAbbreviatedMonthName(3)); 

我不知道這是什麼問題。請幫忙。

回答

3

GetAbbreviatedMonthName是實例方法,所以您必須有一個DateTimeFormatInfo類的實例來調用該方法。

使用DateTimeFormatInfo.CurrentInfo獲得DateTimeFormatInfo實例當前文化:

monList.Add(System.Globalization.DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(3)); 
+0

由於它的工作.... – Dhwani

相關問題