【问题标题】:Convert a string to an enum in C#在 C# 中将字符串转换为枚举
【发布时间】:2010-09-06 04:15:18
【问题描述】:

在 C# 中将字符串转换为枚举值的最佳方法是什么?

我有一个包含枚举值的 HTML 选择标记。页面发布的时候,我想取值(会是字符串的形式),转换成对应的枚举值。

在理想的世界里,我可以这样做:

StatusEnum MyStatus = StatusEnum.Parse("Active");

但这不是有效的代码。

【问题讨论】:

  • 试试这个:Enum.TryParse("Active", out StatusEnum yourStatus);

标签: c# string enums


【解决方案1】:

在某个时候添加了 Parse 的通用版本。对我来说,这更可取,因为我不需要“尝试”解析,而且我还希望结果内联而不生成输出变量。

ColorEnum color = Enum.Parse<ColorEnum>("blue");

MS Documentation: Parse

【讨论】:

    【解决方案2】:

    首先,你需要装饰你的枚举,像这样:

        public enum Store : short
    {
        [Description("Rio Big Store")]
        Rio = 1
    }
    

    在 .net 5 中,我创建了这个扩展方法:

    //The class also needs to be static, ok?
    public static string GetDescription(this System.Enum enumValue)
        {
            FieldInfo fi = enumValue.GetType().GetField(enumValue.ToString());
    
            DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(
                typeof(DescriptionAttribute), false);
    
            if (attributes != null && attributes.Length > 0) return attributes[0].Description;
            else return enumValue.ToString();
        }
    

    现在您可以在任何枚举中使用扩展方法

    像这样:

    var Desc = Store.Rio.GetDescription(); //Store is your Enum
    

    【讨论】:

    • 问题是问如何将字符串解析成枚举,而不是如何将枚举格式化成字符串
    • 恐怕这完全没有抓住重点。
    【解决方案3】:

    在 .NET Core 和 .NET Framework ≥4.0 there is a generic parse method

    Enum.TryParse("Active", out StatusEnum myStatus);
    

    这还包括 C#7 的新内联 out 变量,因此它会尝试解析、转换为显式枚举类型并初始化+填充 myStatus 变量。

    如果您可以访问 C#7 和最新的 .NET,这是最好的方法。

    原答案

    在 .NET 中它相当丑陋(直到 4 或更高版本):

    StatusEnum MyStatus = (StatusEnum) Enum.Parse(typeof(StatusEnum), "Active", true);
    

    我倾向于将其简化为:

    public static T ParseEnum<T>(string value)
    {
        return (T) Enum.Parse(typeof(T), value, true);
    }
    

    那我可以做:

    StatusEnum MyStatus = EnumUtil.ParseEnum<StatusEnum>("Active");
    

    cmets 中建议的一个选项是添加一个扩展,这很简单:

    public static T ToEnum<T>(this string value)
    {
        return (T) Enum.Parse(typeof(T), value, true);
    }
    
    StatusEnum MyStatus = "Active".ToEnum<StatusEnum>();
    

    最后,如果字符串无法解析,您可能希望使用默认枚举:

    public static T ToEnum<T>(this string value, T defaultValue) 
    {
        if (string.IsNullOrEmpty(value))
        {
            return defaultValue;
        }
    
        T result;
        return Enum.TryParse<T>(value, true, out result) ? result : defaultValue;
    }
    

    这是调用的原因:

    StatusEnum MyStatus = "Active".ToEnum(StatusEnum.None);
    

    但是,我会小心地将这样的扩展方法添加到 string,因为(没有命名空间控制)它会出现在 string 的所有实例上,无论它们是否持有枚举(所以 1234.ToString().ToEnum(StatusEnum.None) 将是有效的但荒谬)。通常最好避免使用仅适用于非常特定上下文的额外方法使 Microsoft 的核心类混乱,除非您的整个开发团队非常了解这些扩展的作用。

    【讨论】:

    • 如果性能很重要(始终如此),请查看 Mckenzieg1 给出的以下答案:stackoverflow.com/questions/16100/…
    • @avinashr 对@McKenzieG1 的回答是正确的,但这并不总是很重要。例如,如果您为每个解析进行数据库调用,那么担心枚举解析将是一个毫无意义的微优化。
    • @H.M.我认为扩展在这里不合适——这是一种特殊情况,扩展将适用于 every 字符串。如果你真的想这样做,虽然这将是一个微不足道的改变。
    • Enum.TryParse 怎么样?
    • 非常好。在上一个示例中,您需要一个 where T : 结构。
    【解决方案4】:

    如果您想在 null 或空时使用默认值(例如,从配置文件中检索并且该值不存在时)并在字符串或数字与任何枚举值不匹配时抛出异常。不过,请注意 Timo 的回答中的警告 (https://stackoverflow.com/a/34267134/2454604)。

        public static T ParseEnum<T>(this string s, T defaultValue, bool ignoreCase = false) 
            where T : struct, IComparable, IConvertible, IFormattable//If C# >=7.3: struct, System.Enum 
        {
            if ((s?.Length ?? 0) == 0)
            {
                return defaultValue;
            }
    
            var valid = Enum.TryParse<T>(s, ignoreCase, out T res);
    
            if (!valid || !Enum.IsDefined(typeof(T), res))
            {
                throw new InvalidOperationException(
                    $"'{s}' is not a valid value of enum '{typeof(T).FullName}'!");
            }
            return res;
        }
    

    【讨论】:

      【解决方案5】:

      如果属性名称与您想要的名称不同(即语言差异),您可以这样做:

      MyType.cs

      using System;
      using System.Runtime.Serialization;
      using Newtonsoft.Json;
      using Newtonsoft.Json.Converters;
      
      [JsonConverter(typeof(StringEnumConverter))]
      public enum MyType
      {
          [EnumMember(Value = "person")]
          Person,
          [EnumMember(Value = "annan_deltagare")]
          OtherPerson,
          [EnumMember(Value = "regel")]
          Rule,
      }
      

      EnumExtensions.cs

      using System;
      using Newtonsoft.Json;
      using Newtonsoft.Json.Converters;
      
      public static class EnumExtensions
      {
          public static TEnum ToEnum<TEnum>(this string value) where TEnum : Enum
          {
              var jsonString = $"'{value.ToLower()}'";
              return JsonConvert.DeserializeObject<TEnum>(jsonString, new StringEnumConverter());
          }
      
          public static bool EqualsTo<TEnum>(this string strA, TEnum enumB) where TEnum : Enum
          {
              TEnum enumA;
              try
              {
                  enumA = strA.ToEnum<TEnum>();
              }
              catch
              {
                  return false;
              }
              return enumA.Equals(enumB);
          }
      }
      

      程序.cs

      public class Program
      {
          static public void Main(String[] args) 
          { 
              var myString = "annan_deltagare";
              var myType = myString.ToEnum<MyType>();
              var isEqual = myString.EqualsTo(MyType.OtherPerson);
              //Output: true
          }     
      }
      

      【讨论】:

        【解决方案6】:

        不确定这是什么时候添加的,但是在 Enum 类上现在有一个

        Parse&lt;TEnum&gt;(stringValue)

        在有问题的例子中这样使用:

        var MyStatus = Enum.Parse&lt;StatusEnum &gt;("Active")

        或忽略大小写:

        var MyStatus = Enum.Parse&lt;StatusEnum &gt;("active", true)

        这是它使用的反编译方法:

            [NullableContext(0)]
            public static TEnum Parse<TEnum>([Nullable(1)] string value) where TEnum : struct
            {
              return Enum.Parse<TEnum>(value, false);
            }
        
            [NullableContext(0)]
            public static TEnum Parse<TEnum>([Nullable(1)] string value, bool ignoreCase) where TEnum : struct
            {
              TEnum result;
              Enum.TryParse<TEnum>(value, ignoreCase, true, out result);
              return result;
            }
        

        【讨论】:

        • 这是在 .NET Core 2.0 中添加的(我在 other answer 中写了一点)
        【解决方案7】:

        注意Enum.Parse() 的性能很糟糕,因为它是通过反射实现的。 (Enum.ToString也是如此,反之亦然。)

        如果您需要在性能敏感的代码中将字符串转换为枚举,最好的办法是在启动时创建一个Dictionary&lt;String,YourEnum&gt; 并使用它来进行转换。

        【讨论】:

        • 我在桌面计算机上第一次运行时测量了 3 毫秒来将字符串转换为枚举。 (只是为了说明可怕的程度)。
        • 哇 3ms 是可怕的数量级
        • 能否围绕这个添加代码示例,让我们了解如何替换和使用
        • 如果您的应用程序被 100 万人使用 => 它加起来相当于您消耗的 50 小时人类生命 :) 在单个页面上使用。 :P
        • 虽然 3ms 第一次运行肯定很糟糕,但第二次运行会更好吗?如果每次都是 3 毫秒,那么我们会像瘟疫一样避免它
        【解决方案8】:

        您可以使用默认值扩展接受的答案以避免异常:

        public static T ParseEnum<T>(string value, T defaultValue) where T : struct
        {
            try
            {
                T enumValue;
                if (!Enum.TryParse(value, true, out enumValue))
                {
                    return defaultValue;
                }
                return enumValue;
            }
            catch (Exception)
            {
                return defaultValue;
            }
        }
        

        那你这样称呼它:

        StatusEnum MyStatus = EnumUtil.ParseEnum("Active", StatusEnum.None);
        

        如果默认值不是枚举,则 Enum.TryParse 将失败并抛出被捕获的异常。

        在我们的代码中在很多地方使用这个函数多年之后,添加这个操作会降低性能的信息也许是件好事!

        【讨论】:

        • 我不喜欢默认值。它可能会导致不可预知的结果。
        • 什么时候会抛出异常?
        • @andleer 如果枚举值不适合与默认值相同的枚举类型
        • @Nelly 这里是旧代码,但defaultValue 和方法返回类型都是T 类型。如果类型不同,您将收到编译时错误:“无法从 'ConsoleApp1.Size' 转换为 'ConsoleApp1.Color'”或任何类型。
        • @andleer,很抱歉我最后给你的回答不正确。如果有人使用非枚举类型的默认值调用此函数,则此方法可能会引发 Syste.ArgumentException。使用 c# 7.0,我无法创建 T : Enum 的 where 子句。这就是为什么我通过 try catch 抓住了这种可能性。
        【解决方案9】:
        public TEnum ToEnum<TEnum>(this string value, TEnum defaultValue){
        if (string.IsNullOrEmpty(value))
            return defaultValue;
        
        return Enum.Parse(typeof(TEnum), value, true);}
        

        【讨论】:

          【解决方案10】:
                  <Extension()>
              Public Function ToEnum(Of TEnum)(ByVal value As String, ByVal defaultValue As TEnum) As TEnum
                  If String.IsNullOrEmpty(value) Then
                      Return defaultValue
                  End If
          
                  Return [Enum].Parse(GetType(TEnum), value, True)
              End Function
          

          【讨论】:

            【解决方案11】:

            试试这个示例:

             public static T GetEnum<T>(string model)
                {
                    var newModel = GetStringForEnum(model);
            
                    if (!Enum.IsDefined(typeof(T), newModel))
                    {
                        return (T)Enum.Parse(typeof(T), "None", true);
                    }
            
                    return (T)Enum.Parse(typeof(T), newModel.Result, true);
                }
            
                private static Task<string> GetStringForEnum(string model)
                {
                    return Task.Run(() =>
                    {
                        Regex rgx = new Regex("[^a-zA-Z0-9 -]");
                        var nonAlphanumericData = rgx.Matches(model);
                        if (nonAlphanumericData.Count < 1)
                        {
                            return model;
                        }
                        foreach (var item in nonAlphanumericData)
                        {
                            model = model.Replace((string)item, "");
                        }
                        return model;
                    });
                }
            

            在此示例中,您可以发送每个字符串,并设置您的Enum。如果您的 Enum 有您想要的数据,请将其作为您的 Enum 类型返回。

            【讨论】:

            • 你在每一行覆盖newModel,所以如果它包含破折号,它不会被替换。此外,您不必检查字符串是否包含任何内容,您可以调用 Replace 反正:var newModel = model.Replace("-", "").Replace(" ", "");
            • @LarsKristensen 是的,我们可以创建一个删除非字母数字字符的方法。
            【解决方案12】:

            使用Enum.TryParse&lt;T&gt;(String, T)(≥ .NET 4.0):

            StatusEnum myStatus;
            Enum.TryParse("Active", out myStatus);
            

            使用 C# 7.0 的 parameter type inlining 可以进一步简化它:

            Enum.TryParse("Active", out StatusEnum myStatus);
            

            【讨论】:

            • 添加中间布尔参数以区分大小写,这是迄今为止最安全、最优雅的解决方案。
            • 来吧,你们中有多少人实施了 2008 年的选定答案,只向下滚动并发现这是更好的(现代)答案。
            • @TEK 我实际上更喜欢 2008 年的答案。
            • Enum.TryParse(String, T) 在解析整数字符串时存在缺陷。例如,此代码将成功地将无意义的字符串解析为无意义的枚举:var result = Enum.TryParse&lt;System.DayOfWeek&gt;("55", out var parsedEnum);
            • @MassDotNet 在这种情况下添加:&amp;&amp; Enum.IsDefined(typeof(System.DayOfWeek), parsedEnum) 以确保解析的 Enum 确实存在。
            【解决方案13】:

            您必须使用 Enum.Parse 从 Enum 中获取对象值,然后您必须将对象值更改为特定的枚举值。可以使用 Convert.ChangeType 转换为枚举值。请看下面的代码sn-p

            public T ConvertStringValueToEnum<T>(string valueToParse){
                return Convert.ChangeType(Enum.Parse(typeof(T), valueToParse, true), typeof(T));
            }
            

            【讨论】:

              【解决方案14】:

              使用 TryParse 的超级简单代码:

              var value = "Active";
              
              StatusEnum status;
              if (!Enum.TryParse<StatusEnum>(value, out status))
                  status = StatusEnum.Unknown;
              

              【讨论】:

                【解决方案15】:

                我发现这里没有考虑枚举值具有 EnumMember 值的情况。所以我们开始:

                using System.Runtime.Serialization;
                
                public static TEnum ToEnum<TEnum>(this string value, TEnum defaultValue) where TEnum : struct
                {
                    if (string.IsNullOrEmpty(value))
                    {
                        return defaultValue;
                    }
                
                    TEnum result;
                    var enumType = typeof(TEnum);
                    foreach (var enumName in Enum.GetNames(enumType))
                    {
                        var fieldInfo = enumType.GetField(enumName);
                        var enumMemberAttribute = ((EnumMemberAttribute[]) fieldInfo.GetCustomAttributes(typeof(EnumMemberAttribute), true)).FirstOrDefault();
                        if (enumMemberAttribute?.Value == value)
                        {
                            return Enum.TryParse(enumName, true, out result) ? result : defaultValue;
                        }
                    }
                
                    return Enum.TryParse(value, true, out result) ? result : defaultValue;
                }
                

                该枚举的示例:

                public enum OracleInstanceStatus
                {
                    Unknown = -1,
                    Started = 1,
                    Mounted = 2,
                    Open = 3,
                    [EnumMember(Value = "OPEN MIGRATE")]
                    OpenMigrate = 4
                }
                

                【讨论】:

                  【解决方案16】:

                  这可能有助于提高性能:

                      private static Dictionary<Type, Dictionary<string, object>> dicEnum = new Dictionary<Type, Dictionary<string, object>>();
                      public static T ToEnum<T>(this string value, T defaultValue)
                      {
                          var t = typeof(T);
                          Dictionary<string, object> dic;
                          if (!dicEnum.ContainsKey(t))
                          {
                              dic = new Dictionary<string, object>();
                              dicEnum.Add(t, dic);
                              foreach (var en in Enum.GetValues(t))
                                  dic.Add(en.ToString(), en);
                          }
                          else
                              dic = dicEnum[t];
                          if (!dic.ContainsKey(value))
                              return defaultValue;
                          else
                              return (T)dic[value];
                      }
                  

                  【讨论】:

                  • 您还应该提供性能测试输出,例如使用您的方法将字符串转换为枚举时运行上述代码所花费的时间,如果有人想检查字符串到枚举或枚举到,则使用常规 Enum.Parse C#中的字符串,检查qawithexperts.com/article/c-sharp/…
                  【解决方案17】:

                  注意:

                  enum Example
                  {
                      One = 1,
                      Two = 2,
                      Three = 3
                  }
                  

                  Enum.(Try)Parse() 接受多个以逗号分隔的参数,并将它们与二进制“或”| 组合。你不能禁用它,在我看来你几乎从不想要它。

                  var x = Enum.Parse("One,Two"); // x is now Three
                  

                  即使 Three 未定义,x 仍将获得 int 值 3。更糟糕的是:Enum.Parse() 可以给你一个甚至没有为枚举定义的值!

                  我不想体验用户自愿或非自愿触发此行为的后果。

                  此外,正如其他人所提到的,大型枚举的性能并不理想,即可能值的数量呈线性。

                  我建议如下:

                      public static bool TryParse<T>(string value, out T result)
                          where T : struct
                      {
                          var cacheKey = "Enum_" + typeof(T).FullName;
                  
                          // [Use MemoryCache to retrieve or create&store a dictionary for this enum, permanently or temporarily.
                          // [Implementation off-topic.]
                          var enumDictionary = CacheHelper.GetCacheItem(cacheKey, CreateEnumDictionary<T>, EnumCacheExpiration);
                  
                          return enumDictionary.TryGetValue(value.Trim(), out result);
                      }
                  
                      private static Dictionary<string, T> CreateEnumDictionary<T>()
                      {
                          return Enum.GetValues(typeof(T))
                              .Cast<T>()
                              .ToDictionary(value => value.ToString(), value => value, StringComparer.OrdinalIgnoreCase);
                      }
                  

                  【讨论】:

                  • 事实上,知道Enum.(Try)Parse accepts multiple, comma-separated arguments, and combines them with binary 'or' 非常有用。意味着您可以将枚举值设置为 2 的幂,并且您可以轻松地解析多个布尔标志,例如。 “使用 SSL,不重试,同步”。事实上,这可能就是它的设计目的。
                  • @pcdev 不确定您是否知道,但此功能是为了帮助支持(枚举的标志属性](docs.microsoft.com/en-us/dotnet/csharp/language-reference/…)。
                  【解决方案18】:

                  我喜欢扩展方法解决方案..

                  namespace System
                  {
                      public static class StringExtensions
                      {
                  
                          public static bool TryParseAsEnum<T>(this string value, out T output) where T : struct
                          {
                              T result;
                  
                              var isEnum = Enum.TryParse(value, out result);
                  
                              output = isEnum ? result : default(T);
                  
                              return isEnum;
                          }
                      }
                  }
                  

                  下面是我的测试实现。

                  using static Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
                  using static System.Console;
                  
                  private enum Countries
                      {
                          NorthAmerica,
                          Europe,
                          Rusia,
                          Brasil,
                          China,
                          Asia,
                          Australia
                      }
                  
                     [TestMethod]
                          public void StringExtensions_On_TryParseAsEnum()
                          {
                              var countryName = "Rusia";
                  
                              Countries country;
                              var isCountry = countryName.TryParseAsEnum(out country);
                  
                              WriteLine(country);
                  
                              IsTrue(isCountry);
                              AreEqual(Countries.Rusia, country);
                  
                              countryName = "Don't exist";
                  
                              isCountry = countryName.TryParseAsEnum(out country);
                  
                              WriteLine(country);
                  
                              IsFalse(isCountry);
                              AreEqual(Countries.NorthAmerica, country); // the 1rst one in the enumeration
                          }
                  

                  【讨论】:

                    【解决方案19】:

                    我使用了类(具有解析和性能改进的 Enum 的强类型版本)。我在 GitHub 上找到了它,它也应该适用于 .NET 3.5。它有一些内存开销,因为它缓冲了一个字典。

                    StatusEnum MyStatus = Enum<StatusEnum>.Parse("Active");
                    

                    博文是Enums – Better syntax, improved performance and TryParse in NET 3.5

                    和代码: https://github.com/damieng/DamienGKit/blob/master/CSharp/DamienG.Library/System/EnumT.cs

                    【讨论】:

                      【解决方案20】:

                      您现在可以使用extension methods

                      public static T ToEnum<T>(this string value, bool ignoreCase = true)
                      {
                          return (T) Enum.Parse(typeof (T), value, ignoreCase);
                      }
                      

                      您可以通过以下代码调用它们(这里,FilterType 是枚举类型):

                      FilterType filterType = type.ToEnum<FilterType>();
                      

                      【讨论】:

                      • 我已经更新了它以将值作为对象并将其转换为此方法中的字符串。这样我就可以只取一个 int 值 .ToEnum 而不是字符串。
                      • @SollyM 我会说这是一个可怕的想法,因为这个扩展方法将适用于 所有 对象类型。在我看来,两种扩展方法,一种用于字符串,一种用于 int,会更干净、更安全。
                      • @Svish,这是真的。我这样做的唯一原因是因为我们的代码仅在内部使用,我想避免编写 2 个扩展。而且由于我们唯一一次转换为 Enum 是使用 string 或 int,所以我不认为这是一个问题。
                      • @SollyM 内部与否,我仍然是维护和使用我的代码的人:如果我在每个智能感知菜单中都设置一个 ToEnum,PI 会很恼火,就像你说的那样,因为这是唯一一次你转换为一个枚举是从字符串或整数,你可以很确定你只需要这两种方法。两种方法也不过是一种,尤其是当它们这么小并且是实用程序类型时:P
                      【解决方案21】:

                      Enum.Parse是你的朋友:

                      StatusEnum MyStatus = (StatusEnum)Enum.Parse(typeof(StatusEnum), "Active");
                      

                      【讨论】:

                        【解决方案22】:

                        您正在寻找Enum.Parse

                        SomeEnum enum = (SomeEnum)Enum.Parse(typeof(SomeEnum), "EnumValue");
                        

                        【讨论】:

                          【解决方案23】:
                          public static T ParseEnum<T>(string value)            //function declaration  
                          {
                              return (T) Enum.Parse(typeof(T), value);
                          }
                          
                          Importance imp = EnumUtil.ParseEnum<Importance>("Active");   //function call
                          

                          ====================一个完整的程序====================

                          using System;
                          
                          class Program
                          {
                              enum PetType
                              {
                              None,
                              Cat = 1,
                              Dog = 2
                              }
                          
                              static void Main()
                              {
                          
                              // Possible user input:
                              string value = "Dog";
                          
                              // Try to convert the string to an enum:
                              PetType pet = (PetType)Enum.Parse(typeof(PetType), value);
                          
                              // See if the conversion succeeded:
                              if (pet == PetType.Dog)
                              {
                                  Console.WriteLine("Equals dog.");
                              }
                              }
                          }
                          -------------
                          Output
                          
                          Equals dog.
                          

                          【讨论】:

                            【解决方案24】:
                            // str.ToEnum<EnumType>()
                            T static ToEnum<T>(this string str) 
                            { 
                                return (T) Enum.Parse(typeof(T), str);
                            }
                            

                            【讨论】:

                              【解决方案25】:

                              在 .NET 4.5 中不使用 try/catch 和 TryParse() 方法将字符串解析为 TEnum

                              /// <summary>
                              /// Parses string to TEnum without try/catch and .NET 4.5 TryParse()
                              /// </summary>
                              public static bool TryParseToEnum<TEnum>(string probablyEnumAsString_, out TEnum enumValue_) where TEnum : struct
                              {
                                  enumValue_ = (TEnum)Enum.GetValues(typeof(TEnum)).GetValue(0);
                                  if(!Enum.IsDefined(typeof(TEnum), probablyEnumAsString_))
                                      return false;
                              
                                  enumValue_ = (TEnum) Enum.Parse(typeof(TEnum), probablyEnumAsString_);
                                  return true;
                              }
                              

                              【讨论】:

                              • 如果代码已经包含描述,是否需要进行描述?好的,我做到了:)
                              【解决方案26】:

                              我们无法假设完全有效的输入,并采用了@Keith 答案的这种变体:

                              public static TEnum ParseEnum<TEnum>(string value) where TEnum : struct
                              {
                                  TEnum tmp; 
                                  if (!Enum.TryParse<TEnum>(value, true, out tmp))
                                  {
                                      tmp = new TEnum();
                                  }
                                  return tmp;
                              }
                              

                              【讨论】:

                                【解决方案27】:
                                object Enum.Parse(System.Type enumType, string value, bool ignoreCase);
                                

                                因此,如果您有一个名为 mood 的枚举,它将如下所示:

                                   enum Mood
                                   {
                                      Angry,
                                      Happy,
                                      Sad
                                   } 
                                
                                   // ...
                                   Mood m = (Mood) Enum.Parse(typeof(Mood), "Happy", true);
                                   Console.WriteLine("My mood is: {0}", m.ToString());

                                【讨论】:

                                  猜你喜欢
                                  • 2015-06-10
                                  • 1970-01-01
                                  • 2013-01-23
                                  • 1970-01-01
                                  • 2010-10-03
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 2010-11-06
                                  相关资源
                                  最近更新 更多