簡體   English   中英

GetAbbreviatedMonthName中的非靜態字段,方法或屬性需要對象引用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM