[英]An object reference is required for the non-static field, method, or property in 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));
我不知道這是什么問題。 請幫忙。
GetAbbreviatedMonthName
是實例方法,因此您必須具有DateTimeFormatInfo
類的實例才能調用該方法。
使用DateTimeFormatInfo.CurrentInfo
獲取當前區域性的DateTimeFormatInfo
實例:
monList.Add(System.Globalization.DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(3));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.