System.String.ToLower 方法

方法描述

返回此字符串转换为小写形式的副本。

语法定义(C# System.String.ToLower 方法 的用法)

public string ToLower()

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
返回值 System.String 一个小写字符串。

提示和注释

此方法考虑当前区域性的大小写规则。

注意

此方法不修改当前实例的值。 而是返回一个新字符串,在该字符串中,当前实例中的所有字符都会转换为小写。

安全注意事项

如果您需要操作系统标识符(如文件名、命名管道或注册表项)的小写或大写版本,请使用 ToLowerInvariant 或 ToUpperInvariant 方法。

对调用者的说明

如在 在 .NET Framework 中使用字符串的最佳做法 中说明的那样,我们建议您避免调用替代默认值的字符串大小写方法,而是调用需要明确指定的参数的方法。 若要使用当前区域性的大小写约定将字符转换为小写,请为它的 culture 参数使用 CultureInfo.CurrentCulture 的值来调用 ToLower(CultureInfo) 方法重载。

System.String.ToLower 方法例子

下面的示例将几个大小写混合的字符串转换为小写。

using System;

public class ToLowerTest {
    public static void Main() {

        string [] info = {"Name", "Title", "Age", "Location", "Gender"};

        Console.WriteLine("The initial values in the array are:");
        foreach (string s in info)
            Console.WriteLine(s);

        Console.WriteLine("{0}The lowercase of these values is:", Environment.NewLine);        

        foreach (string s in info)
            Console.WriteLine(s.ToLower());

        Console.WriteLine("{0}The uppercase of these values is:", Environment.NewLine);        

        foreach (string s in info)
            Console.WriteLine(s.ToUpper());
    }
}
// The example displays the following output:
//       The initial values in the array are:
//       Name
//       Title
//       Age
//       Location
//       Gender
//       
//       The lowercase of these values is:
//       name
//       title
//       age
//       location
//       gender
//       
//       The uppercase of these values is:
//       NAME
//       TITLE
//       AGE
//       LOCATION
//       GENDER

异常

异常 异常描述

命名空间

namespace: System

程序集: mscorlib(在 mscorlib.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。