CultureInfo 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
특정 문화권(비관리 코드 개발의 경우 로캘 이라고 함)에 대한 정보를 제공합니다. 이 정보에는 문화권 이름, 쓰기 시스템, 사용된 달력, 문자열의 정렬 순서, 날짜 및 숫자 형식이 포함되어 있습니다.
public ref class CultureInfo : IFormatProvider
public ref class CultureInfo : ICloneable, IFormatProvider
public class CultureInfo : IFormatProvider
public class CultureInfo : ICloneable, IFormatProvider
[System.Serializable]
public class CultureInfo : ICloneable, IFormatProvider
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class CultureInfo : ICloneable, IFormatProvider
type CultureInfo = class
interface IFormatProvider
type CultureInfo = class
interface ICloneable
interface IFormatProvider
[<System.Serializable>]
type CultureInfo = class
interface ICloneable
interface IFormatProvider
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type CultureInfo = class
interface ICloneable
interface IFormatProvider
Public Class CultureInfo
Implements IFormatProvider
Public Class CultureInfo
Implements ICloneable, IFormatProvider
- 상속
-
CultureInfo
- 특성
- 구현
예제
다음 예제에서는 만드는 방법을 보여 있습니다는 CultureInfo 스페인어 (스페인)에 대 한 개체 국제 정렬 및 다른 개체를 사용 하 고 CultureInfo 기존 정렬 합니다.
using namespace System;
using namespace System::Collections;
using namespace System::Globalization;
int main()
{
// Creates and initializes the CultureInfo which uses the international sort.
CultureInfo^ myCIintl = gcnew CultureInfo( "es-ES",false );
// Creates and initializes the CultureInfo which uses the traditional sort.
CultureInfo^ myCItrad = gcnew CultureInfo( 0x040A,false );
// Displays the properties of each culture.
Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL" );
Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "CompareInfo", myCIintl->CompareInfo, myCItrad->CompareInfo );
Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "DisplayName", myCIintl->DisplayName, myCItrad->DisplayName );
Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "EnglishName", myCIintl->EnglishName, myCItrad->EnglishName );
Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "IsNeutralCulture", myCIintl->IsNeutralCulture, myCItrad->IsNeutralCulture );
Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "IsReadOnly", myCIintl->IsReadOnly, myCItrad->IsReadOnly );
Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "LCID", myCIintl->LCID, myCItrad->LCID );
Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "Name", myCIintl->Name, myCItrad->Name );
Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "NativeName", myCIintl->NativeName, myCItrad->NativeName );
Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "Parent", myCIintl->Parent, myCItrad->Parent );
Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "TextInfo", myCIintl->TextInfo, myCItrad->TextInfo );
Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "ThreeLetterISOLanguageName", myCIintl->ThreeLetterISOLanguageName, myCItrad->ThreeLetterISOLanguageName );
Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl->ThreeLetterWindowsLanguageName, myCItrad->ThreeLetterWindowsLanguageName );
Console::WriteLine( "{0,-31}{1,-47}{2,-25}", "TwoLetterISOLanguageName", myCIintl->TwoLetterISOLanguageName, myCItrad->TwoLetterISOLanguageName );
Console::WriteLine();
// Compare two strings using myCIintl ->
Console::WriteLine( "Comparing \"llegar\" and \"lugar\"" );
Console::WriteLine( " With myCIintl -> CompareInfo -> Compare: {0}", myCIintl->CompareInfo->Compare( "llegar", "lugar" ) );
Console::WriteLine( " With myCItrad -> CompareInfo -> Compare: {0}", myCItrad->CompareInfo->Compare( "llegar", "lugar" ) );
}
/*
This code produces the following output.
PROPERTY INTERNATIONAL TRADITIONAL
CompareInfo CompareInfo - es-ES CompareInfo - es-ES_tradnl
DisplayName Spanish (Spain) Spanish (Spain)
EnglishName Spanish (Spain, International Sort) Spanish (Spain, Traditional Sort)
IsNeutralCulture False False
IsReadOnly False False
LCID 3082 1034
Name es-ES es-ES
NativeName Español (España, alfabetización internacional) Español (España, alfabetización tradicional)
Parent es es
TextInfo TextInfo - es-ES TextInfo - es-ES_tradnl
ThreeLetterISOLanguageName spa spa
ThreeLetterWindowsLanguageName ESN ESP
TwoLetterISOLanguageName es es
Comparing "llegar" and "lugar"
With myCIintl -> CompareInfo -> Compare: -1
With myCItrad -> CompareInfo -> Compare: 1
*/
using System;
using System.Collections;
using System.Globalization;
public class SamplesCultureInfo
{
public static void Main()
{
// Creates and initializes the CultureInfo which uses the international sort.
CultureInfo myCIintl = new CultureInfo("es-ES", false);
// Creates and initializes the CultureInfo which uses the traditional sort.
CultureInfo myCItrad = new CultureInfo(0x040A, false);
// Displays the properties of each culture.
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL");
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "CompareInfo", myCIintl.CompareInfo, myCItrad.CompareInfo);
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "DisplayName", myCIintl.DisplayName, myCItrad.DisplayName);
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "EnglishName", myCIintl.EnglishName, myCItrad.EnglishName);
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "IsNeutralCulture", myCIintl.IsNeutralCulture, myCItrad.IsNeutralCulture);
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "IsReadOnly", myCIintl.IsReadOnly, myCItrad.IsReadOnly);
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "LCID", myCIintl.LCID, myCItrad.LCID);
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "Name", myCIintl.Name, myCItrad.Name);
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "NativeName", myCIintl.NativeName, myCItrad.NativeName);
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "Parent", myCIintl.Parent, myCItrad.Parent);
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "TextInfo", myCIintl.TextInfo, myCItrad.TextInfo);
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "ThreeLetterISOLanguageName", myCIintl.ThreeLetterISOLanguageName, myCItrad.ThreeLetterISOLanguageName);
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl.ThreeLetterWindowsLanguageName, myCItrad.ThreeLetterWindowsLanguageName);
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "TwoLetterISOLanguageName", myCIintl.TwoLetterISOLanguageName, myCItrad.TwoLetterISOLanguageName);
Console.WriteLine();
// Compare two strings using myCIintl.
Console.WriteLine("Comparing \"llegar\" and \"lugar\"");
Console.WriteLine(" With myCIintl.CompareInfo.Compare: {0}", myCIintl.CompareInfo.Compare("llegar", "lugar"));
Console.WriteLine(" With myCItrad.CompareInfo.Compare: {0}", myCItrad.CompareInfo.Compare("llegar", "lugar"));
}
}
/*
This code produces the following output.
PROPERTY INTERNATIONAL TRADITIONAL
CompareInfo CompareInfo - es-ES CompareInfo - es-ES_tradnl
DisplayName Spanish (Spain) Spanish (Spain)
EnglishName Spanish (Spain, International Sort) Spanish (Spain, Traditional Sort)
IsNeutralCulture False False
IsReadOnly False False
LCID 3082 1034
Name es-ES es-ES
NativeName Español (España, alfabetización internacional) Español (España, alfabetización tradicional)
Parent es es
TextInfo TextInfo - es-ES TextInfo - es-ES_tradnl
ThreeLetterISOLanguageName spa spa
ThreeLetterWindowsLanguageName ESN ESP
TwoLetterISOLanguageName es es
Comparing "llegar" and "lugar"
With myCIintl.CompareInfo.Compare: -1
With myCItrad.CompareInfo.Compare: 1
*/
Imports System.Collections
Imports System.Globalization
Module Module1
Public Sub Main()
' Creates and initializes the CultureInfo which uses the international sort.
Dim myCIintl As New CultureInfo("es-ES", False)
' Creates and initializes the CultureInfo which uses the traditional sort.
Dim myCItrad As New CultureInfo(&H40A, False)
' Displays the properties of each culture.
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL")
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "CompareInfo", myCIintl.CompareInfo, myCItrad.CompareInfo)
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "DisplayName", myCIintl.DisplayName, myCItrad.DisplayName)
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "EnglishName", myCIintl.EnglishName, myCItrad.EnglishName)
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "IsNeutralCulture", myCIintl.IsNeutralCulture, myCItrad.IsNeutralCulture)
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "IsReadOnly", myCIintl.IsReadOnly, myCItrad.IsReadOnly)
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "LCID", myCIintl.LCID, myCItrad.LCID)
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "Name", myCIintl.Name, myCItrad.Name)
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "NativeName", myCIintl.NativeName, myCItrad.NativeName)
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "Parent", myCIintl.Parent, myCItrad.Parent)
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "TextInfo", myCIintl.TextInfo, myCItrad.TextInfo)
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "ThreeLetterISOLanguageName", myCIintl.ThreeLetterISOLanguageName, myCItrad.ThreeLetterISOLanguageName)
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl.ThreeLetterWindowsLanguageName, myCItrad.ThreeLetterWindowsLanguageName)
Console.WriteLine("{0,-31}{1,-47}{2,-25}", "TwoLetterISOLanguageName", myCIintl.TwoLetterISOLanguageName, myCItrad.TwoLetterISOLanguageName)
Console.WriteLine()
' Compare two strings using myCIintl.
Console.WriteLine("Comparing ""llegar"" and ""lugar""")
Console.WriteLine(" With myCIintl.CompareInfo.Compare: {0}", myCIintl.CompareInfo.Compare("llegar", "lugar"))
Console.WriteLine(" With myCItrad.CompareInfo.Compare: {0}", myCItrad.CompareInfo.Compare("llegar", "lugar"))
End Sub
'This code produces the following output.
'
'PROPERTY INTERNATIONAL TRADITIONAL
'CompareInfo CompareInfo - es-ES CompareInfo - es-ES_tradnl
'DisplayName Spanish (Spain) Spanish (Spain)
'EnglishName Spanish (Spain, International Sort) Spanish (Spain, Traditional Sort)
'IsNeutralCulture False False
'IsReadOnly False False
'LCID 3082 1034
'Name es-ES es-ES
'NativeName Español (España, alfabetización internacional) Español (España, alfabetización tradicional)
'Parent es es
'TextInfo TextInfo - es-ES TextInfo - es-ES_tradnl
'ThreeLetterISOLanguageName spa spa
'ThreeLetterWindowsLanguageName ESN ESP
'TwoLetterISOLanguageName es es
'
'Comparing "llegar" and "lugar"
' With myCIintl.CompareInfo.Compare: -1
' With myCItrad.CompareInfo.Compare: 1
End Module
설명
CultureInfo클래스는 언어, 하위 언어, 국가/지역, 달력 및 특정 문화권과 관련 된 규칙과 같은 문화권별 정보를 제공 합니다. 또한이 클래스는,, 및 개체의 문화권별 인스턴스에 대 한 액세스를 제공 DateTimeFormatInfo NumberFormatInfo CompareInfo TextInfo 합니다. 이러한 개체에는 대/소문자 구분, 날짜 및 숫자 서식 지정 및 문자열 비교와 같은 문화권 관련 작업에 필요한 정보가 포함 됩니다. CultureInfo클래스는 String ,, DateTime DateTimeOffset 및 숫자 형식과 같은 문화권별 데이터의 형식을 지정, 구문 분석 또는 조작 하는 클래스에 의해 직접 또는 간접적으로 사용 됩니다.
이 섹션에서는 다음 작업을 수행합니다.
문화권 이름 및 식별자
고정, 중립 및 특정 문화권
사용자 지정 문화권
동적 문화권 데이터
CultureInfo 및 culture 데이터
현재 문화권 및 현재 UI 문화권
모든 문화권 가져오기
문화권 및 스레드
Culture 및 응용 프로그램 도메인
문화권 및 작업 기반 비동기 작업
CultureInfo 개체 serialization
제어판 재정의
대체 정렬 순서
Culture 및 Windows apps\
문화권 이름 및 식별자
CultureInfo클래스는 RFC 4646을 기반으로 각 문화권의 고유 이름을 지정 합니다. 이름에는 언어와 관련 된 ISO 639 두 문자의 소문자 문화권 코드를 한 국가 또는 지역에 연결 된 ISO 3166 두 문자의 대문자 하위 문화권 코드를 조합입니다. 또한 .NET Framework 4 이상을 대상으로 하 고 Windows 10 이상에서 실행 되는 앱의 경우 유효한 BCP-47 언어 태그에 해당 하는 문화권 이름이 지원 됩니다.
참고
문화권 이름이 또는와 같은 메서드 또는 클래스 생성자에 전달 되 면 CreateSpecificCulture CultureInfo 해당 사례는 중요 하지 않습니다.
RFC 4646을 기반으로 하는 문화권 이름의 형식은입니다 languagecode2 - country/regioncode2 . 여기서 languagecode2 는 두 문자로 된 언어 코드이 고 country/regioncode2 는 두 문자로 된 하위 문화권 코드입니다. 예를 들면 ja-JP 일본어 (일본) 및 en-US 영어 (미국)가 포함 됩니다. 2자 언어 코드를 사용할 수 없는 경우 ISO 639-2에서 파생된 3자 코드가 사용됩니다.
일부 문화권 이름에는 ISO 15924 스크립트도 지정 됩니다. 예를 들어 Cyrl는 키릴 자모 스크립트를 지정 하 고 Latn은 라틴어 스크립트를 지정 합니다. 스크립트를 포함 하는 문화권 이름은 패턴을 사용 languagecode2 - scripttag - country/regioncode2 합니다. 이 문화권 이름 형식의 예는 uz-Cyrl-UZ 우즈베크어 (키릴 자모, 우즈베키스탄) 용입니다. Vista Windows 이전에 Windows 운영 체제에서 스크립트가 포함 된 문화권 이름은 예를 들어 languagecode2 - country/regioncode2 - scripttag uz-UZ-Cyrl 우즈베크어 (키릴 자모, 우즈베키스탄)와 같은 패턴을 사용 합니다.
중립 문화권은 2 자 소문자 언어 코드로만 지정 됩니다. 예를 들어는 fr 프랑스어의 중립 문화권을 지정 하 고는 de 독일어의 중립 문화권을 지정 합니다.
참고
이 규칙과 일치 하지 않는 두 가지 문화권 이름이 있습니다. 중국어 (간체), 명명 된 zh-Hans 및 중국어 (번체) 문화권은 zh-Hant 중립 문화권입니다. 문화권 이름은 현재 표준을 나타내므로 이전 이름 및를 사용 해야 하는 이유가 없으면 사용 해야 합니다 zh-CHS zh-CHT .
문화권 식별자는 표준 국제 숫자 약어 이며 설치 된 문화권 중 하나를 고유 하 게 식별 하는 데 필요한 구성 요소를 포함 합니다. 애플리케이션은 미리 정의 된 문화권 식별자를 사용 하거나 사용자 지정 식별자를 정의할 수 있습니다.
미리 정의 된 특정 문화권 이름 및 식별자는이 클래스 및 네임 스페이스의 다른 클래스에서 사용 됩니다 System.Globalization . Windows 시스템에 대 한 자세한 culture 정보는 Windows에서 지 원하는 언어/지역 이름 목록의 언어 태그 열을 참조 하세요. 문화권 이름은 BCP 47에 정의된 표준을 따릅니다.
문화권 이름 및 식별자는 특정 컴퓨터에서 찾을 수 있는 문화권의 하위 집합만을 나타냅니다. Windows 버전 또는 서비스 팩은 사용 가능한 문화권을 변경할 수 있습니다. 응용 프로그램은 클래스를 사용 하 여 사용자 지정 문화권을 추가할 수 있습니다 CultureAndRegionInfoBuilder . 사용자는 Microsoft Locale Builder 도구를 사용 하 여 고유한 사용자 지정 문화권을 추가할 수 있습니다. Microsoft Locale Builder는 클래스를 사용 하 여 관리 코드로 작성 됩니다 CultureAndRegionInfoBuilder .
다음과 같은 클래스 멤버와 관련 된 이름과 같이 여러 개의 고유 이름이 문화권과 밀접 하 게 연결 되어 있습니다.
고정, 중립, 특정 문화권
일반적으로 문화권은 고정 문화권, 중립 문화권 및 특정 문화권의 세 가지 집합으로 그룹화 됩니다.
고정 문화권은 문화권을 구분 하지 않습니다. 빈 문자열을 사용 하 여 이름 고정 문화권을 지정 하는 애플리케이션 ("") 또는 해당 id에서 합니다. InvariantCulture 고정 문화권의 인스턴스를 정의 합니다. 영어와 연결 되어 있지만 국가/지역과는 관련이 없습니다. 문화권이 필요한 네임 스페이스의 거의 모든 메서드에서 사용 됩니다 Globalization .
중립 문화권은 언어와 연결 되어 있지만 국가/지역이 아닌 문화권입니다. 특정 문화권은 언어 및 국가/지역과 연결 된 문화권입니다. 예를 들어 fr 는 프랑스어 문화권의 중립 이름이 고 fr-FR 는 특정 프랑스어 (프랑스) 문화권의 이름입니다. 중국어 (간체) 및 중국어 (번체)도 중립 문화권으로 간주 됩니다.
CompareInfo중립 문화권에 대 한 클래스의 인스턴스를 만드는 것은 해당 클래스에 포함 된 데이터가 임의적 이므로 권장 되지 않습니다. 데이터를 표시 하 고 정렬 하려면 언어와 지역을 모두 지정 합니다. 또한 Name CompareInfo 중립 문화권에 대해 만들어진 개체의 속성은 국가만 반환 하 고 지역은 포함 하지 않습니다.
정의 된 문화권에는 특정 문화권의 부모가 중립 문화권이 고 중립 문화권의 부모가 고정 문화권 인 계층이 있습니다. 속성에는 Parent 특정 문화권과 연결 된 중립 문화권이 포함 되어 있습니다. 사용자 지정 문화권은 Parent 이 패턴을 준수 하 여 속성을 정의 해야 합니다.
특정 문화권에 대 한 리소스를 운영 체제에서 사용할 수 없는 경우 연결 된 중립 문화권에 대 한 리소스가 사용 됩니다. 중립 문화권에 대 한 리소스를 사용할 수 없는 경우에 주 어셈블리에 포함 된 리소스 사용 됩니다. 리소스 대체 프로세스에 대 한 자세한 내용은 리소스 패키징 및 배포를 참조 하세요.
Windows API의 로캘 목록은 .net에서 지 원하는 문화권 목록과 약간 다릅니다. 예를 들어 p/invoke 메커니즘을 통해 Windows와의 상호 운용성이 필요한 경우 응용 프로그램은 운영 체제에 대해 정의 된 특정 문화권을 사용 해야 합니다. 특정 문화권을 사용 하면와 동일한 로캘 식별자로 식별 되는 동등한 Windows 로캘과의 일관성이 유지 됩니다 LCID .
DateTimeFormatInfo또는는 NumberFormatInfo 고정 문화권 또는 중립 문화권이 아닌 특정 문화권에 대해서만 만들 수 있습니다.
DateTimeFormatInfo.Calendar가 이지만이 TaiwanCalendar Thread.CurrentCulture 로 설정 되지 않은 경우, zh-TW 및은 DateTimeFormatInfo.NativeCalendarName DateTimeFormatInfo.GetEraName DateTimeFormatInfo.GetAbbreviatedEraName 빈 문자열 ("")을 반환 합니다.
사용자 지정 문화권
Windows에서 사용자 지정 로캘을 만들 수 있습니다. 자세한 내용은 사용자 지정 로캘을 참조 하세요.
CultureInfo 및 culture 데이터
.NET은 구현, 플랫폼 및 버전에 따라 다양 한 소스 중 하나에서 해당 문화권 데이터를 파생 시킵니다.
.NET Framework 3.5 이전 버전에서 문화권 데이터는 Windows 운영 체제와 .NET Framework에서 제공 됩니다.
.NET Framework 4 이상 버전에서는 Windows 운영 체제에서 문화권 데이터를 제공 합니다.
Windows에서 실행 되는 모든 버전의 .net Core에서 문화권 데이터는 Windows 운영 체제에서 제공 됩니다.
Unix 플랫폼에서 실행 되는 모든 버전의 .NET Core에서 문화권 데이터는 유니코드 (ICU) 라이브러리에 대 한 국제 구성 요소에 의해 제공 됩니다. 특정 버전의 ICU 라이브러리는 개별 운영 체제에 따라 달라 집니다.
따라서 특정 .NET 구현, 플랫폼 또는 버전에서 사용할 수 있는 문화권은 다른 .NET 구현, 플랫폼 또는 버전에서 사용 하지 못할 수 있습니다.
일부 CultureInfo 개체는 기본 플랫폼에 따라 달라 집니다. 특히, zh-CN 또는 중국어 (간체, 중국) 및 zh-TW 또는 중국어 (번체, 대만)는 Windows 시스템에서 사용할 수 있는 문화권 이지만 Unix 시스템에서는 별칭이 지정 된 문화권입니다. "zh-cn"은 "zh-cn-Hans-CN" 문화권에 대 한 별칭이 고 "zh-cn"는 "zh-cn-Zh-hant" 문화권의 별칭입니다. 별칭이 지정 된 문화권은 메서드에 대 한 호출에서 반환 되지 않으며 GetCultures , 다른 문화권을 포함 하 여 다른 속성 값 (Windows 상응 하는 문화권)을 가질 수 있습니다 Parent . zh-CN및 문화권의 경우 zh-TW 이러한 differenes에는 다음이 포함 됩니다.
Windows 시스템에서 "zh-cn" 문화권의 부모 문화권은 "zh-cn-Hans"이 고, "zh-cn" 문화권의 부모 문화권은 "zh-cn-zh-hant"입니다. 이러한 두 문화권의 부모 문화권은 모두 "zh-cn"입니다. Unix 시스템에서 두 문화권의 부모는 "zh-cn"입니다. 즉, "zh-cn" 또는 "zh-cn" 문화권에 대 한 문화권별 리소스를 제공 하지 않지만 중립 "zh-cn-Hans" 또는 "zh-cn" 문화권에 대 한 리소스를 제공 하지 않는 경우 응용 프로그램은 Windows에서 중립 문화권에 대 한 리소스를 로드 하지만 Unix에서는 로드 하지 않습니다. Unix 시스템에서는 스레드를 CurrentUICulture "zh-cn-Hans" 또는 "zh-cn-zh-hant"로 명시적으로 설정 해야 합니다.
Windows 시스템에서 CultureInfo.Equals "zh-cn" 문화권을 나타내는 인스턴스에서를 호출 하 고 "zh-cn-Hans-cn" 인스턴스를 전달 하면이 반환
true됩니다. Unix 시스템에서 메서드 호출은를 반환 합니다false. 이 동작은 "zh-cn" 인스턴스에서를 호출 하 Equals CultureInfo 고 "Zh-cn-zh-hant" 인스턴스를 전달 하는 데에도 적용 됩니다.
동적 문화권 데이터
고정 문화권의 경우를 제외하고 문화권 데이터는 동적입니다. 이는 미리 정의된 문화권에서도 마찬가지입니다. 예를 들어 국가 또는 지역은 새 통화를 채택하거나, 단어의 철자를 변경하거나, 기본 달력을 변경하고, 문화권 정의를 변경하여 이를 추적합니다. 사용자 지정 문화권은 통지 없이 변경될 수 있으며, 특정 문화권은 사용자 지정 대체 문화권에 의해 재정의될 수 있습니다. 또한 아래에서 설명한 대로 개별 사용자는 문화권 기본 설정을 재정의할 수 있습니다. 애플리케이션 런타임 시 culture 데이터를 항상 가져오기 해야 합니다.
주의
데이터를 저장할 때 애플리케이션은 고정 문화권, 이진 형식으로 또는 특정 문화권에 독립적인 형식을 사용 해야 합니다. 고정 문화권이 아닌 특정 문화권과 연결된 현재 값에 따라 저장된 데이터는 읽을 수 없게 되거나 문화권이 변경될 경우 의미가 변경될 수 있습니다.
현재 문화권 및 현재 UI 문화권
.NET 애플리케이션의 모든 스레드에는 현재 문화권과 현재 UI 문화권이 있습니다. 현재 문화권은 날짜, 시간, 숫자 및 통화 값에 대한 서식 지정 규칙, 텍스트 정렬 순서, 대/소문자 구분 규칙 및 문자열을 비교하는 방법을 결정합니다. 현재 UI 문화권은 런타임에 문화권별 리소스를 검색하는 데 사용됩니다.
참고
현재 및 현재 UI 문화권이 스레드별로 결정되는 방법에 대한 자세한 내용은 문화권 및 스레드 섹션을 참조하세요. 스레드에서 현재 및 현재 UI 문화권을 결정 하는 방법을 알아보려면 참조는 새 애플리케이션 도메인에 애플리케이션 도메인 경계를 교차 하는 스레드를 실행 합니다 문화권 및 애플리케이션 도메인 섹션입니다. 작업 기반 비동기 작업을 수행하는 스레드에서 현재 및 현재 가 결정되는 방식에 대한 자세한 내용은 문화권 및 작업 기반 비동기 작업 섹션을 참조하세요.
현재 문화권에 대 한 자세한 내용은 참조는 CultureInfo.CurrentCulture 속성 항목입니다. 현재 UI 문화권에 대 한 자세한 내용은 참조는 CultureInfo.CurrentUICulture 속성 항목입니다.
현재 및 현재 UI 문화권 검색
다음 두 가지 방법 중 하나를 통해 CultureInfo 현재 문화권 을 나타내는 개체를 얻을 수 있습니다.
값을 검색 하 여 CultureInfo.CurrentCulture 속성입니다.
Thread.CurrentThread.CurrentCulture 속성의 값을 검색합니다.
다음 예제에서는 두 속성 값을 검색하고, 두 값을 비교하여 같은지 표시하고, 현재 문화권의 이름을 표시합니다.
using System;
using System.Globalization;
using System.Threading;
public class Example
{
public static void Main()
{
CultureInfo culture1 = CultureInfo.CurrentCulture;
CultureInfo culture2 = Thread.CurrentThread.CurrentCulture;
Console.WriteLine("The current culture is {0}", culture1.Name);
Console.WriteLine("The two CultureInfo objects are equal: {0}",
culture1 == culture2);
}
}
// The example displays output like the following:
// The current culture is en-US
// The two CultureInfo objects are equal: True
Imports System.Globalization
Imports System.Threading
Module Example
Public Sub Main()
Dim culture1 As CultureInfo = CultureInfo.CurrentCulture
Dim culture2 As CultureInfo = Thread.CurrentThread.CurrentCulture
Console.WriteLine("The current culture is {0}", culture1.Name)
Console.WriteLine("The two CultureInfo objects are equal: {0}",
culture1.Equals(culture2))
End Sub
End Module
' The example displays output like the following:
' The current culture is en-US
' The two CultureInfo objects are equal: True
다음 두 가지 방법 중 하나를 통해 CultureInfo 현재 UI 문화권 을 나타내는 개체를 얻을 수 있습니다.
값을 검색 하 여 CultureInfo.CurrentUICulture 속성입니다.
Thread.CurrentThread.CurrentUICulture 속성의 값을 검색합니다.
다음 예제에서는 두 속성 값을 검색하고, 두 값을 비교하여 같은지 표시하고, 현재 UI 문화권의 이름을 표시합니다.
using System;
using System.Globalization;
using System.Threading;
public class Example
{
public static void Main()
{
CultureInfo uiCulture1 = CultureInfo.CurrentUICulture;
CultureInfo uiCulture2 = Thread.CurrentThread.CurrentUICulture;
Console.WriteLine("The current UI culture is {0}", uiCulture1.Name);
Console.WriteLine("The two CultureInfo objects are equal: {0}",
uiCulture1 == uiCulture2);
}
}
// The example displays output like the following:
// The current UI culture is en-US
// The two CultureInfo objects are equal: True
Imports System.Globalization
Imports System.Threading
Module Example
Public Sub Main()
Dim uiCulture1 As CultureInfo = CultureInfo.CurrentUICulture
Dim uiCulture2 As CultureInfo = Thread.CurrentThread.CurrentUICulture
Console.WriteLine("The current UI culture is {0}", uiCulture1.Name)
Console.WriteLine("The two CultureInfo objects are equal: {0}",
uiCulture1.Equals(uiCulture2))
End Sub
End Module
' The example displays output like the following:
' The current UI culture is en-US
' The two CultureInfo objects are equal: True
현재 및 현재 UI 문화권 설정
스레드의 문화권 및 UI 문화권 변경하려면 다음을 수행합니다.
CultureInfo CultureInfo 클래스 생성자를 호출하고 문화권의 이름을 전달하여 해당 문화권에 해당하는 개체를 인스턴스화합니다. CultureInfo(String)생성자는 CultureInfo 새 문화권이 현재 Windows 문화권과 동일한 경우 사용자 재정의를 반영하는 개체를 인스턴스화합니다. CultureInfo(String, Boolean)생성자를 사용하면 새 문화권이 현재 Windows 문화권과 동일한 경우 새로 인스턴스화된 CultureInfo 개체가 사용자 재정의를 반영하는지 여부를 지정할 수 있습니다.
CultureInfo CultureInfo.CurrentCulture CultureInfo.CurrentUICulture .NET Core 및 .NET Framework 4.6 이상 버전에서 또는 속성에 개체를 할당합니다. (.NET Framework 4.5.2 및 이전 버전에서는
CultureInfo개체를 또는 속성에 할당할 수 Thread.CurrentCulture Thread.CurrentUICulture 있습니다.)
다음 예제에서는 현재 문화권 검색 합니다. 프랑스어(프랑스) 문화권 이외의 문화권인 경우 현재 문화권이 프랑스어(프랑스)로 변경됩니다. 그렇지 않으면 현재 문화권이 프랑스어(프랑스)로 변경됩니다.
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
CultureInfo current = CultureInfo.CurrentCulture;
Console.WriteLine("The current culture is {0}", current.Name);
CultureInfo newCulture;
if (current.Name.Equals("fr-FR"))
newCulture = new CultureInfo("fr-LU");
else
newCulture = new CultureInfo("fr-FR");
CultureInfo.CurrentCulture = newCulture;
Console.WriteLine("The current culture is now {0}",
CultureInfo.CurrentCulture.Name);
}
}
// The example displays output like the following:
// The current culture is en-US
// The current culture is now fr-FR
Imports System.Globalization
Module Example
Public Sub Main()
Dim current As CultureInfo = CultureInfo.CurrentCulture
Console.WriteLine("The current culture is {0}", current.Name)
Dim newCulture As CultureInfo
If current.Name.Equals("fr-FR") Then
newCulture = New CultureInfo("fr-LU")
Else
newCulture = new CultureInfo("fr-FR")
End If
CultureInfo.CurrentCulture = newCulture
Console.WriteLine("The current culture is now {0}",
CultureInfo.CurrentCulture.Name)
End Sub
End Module
' The example displays output like the following:
' The current culture is en-US
' The current culture is now fr-FR
다음 예제에서는 현재 문화권 검색 합니다. 다른 문화권인 경우 현재 문화권이 표시되면 현재 문화권이 2018년 3월 12일로 변경됩니다. 그렇지 않으면 현재 문화권이 세르비아어(세르비아)로 변경됩니다.
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
CultureInfo current = CultureInfo.CurrentUICulture;
Console.WriteLine("The current UI culture is {0}", current.Name);
CultureInfo newUICulture;
if (current.Name.Equals("sl-SI"))
newUICulture = new CultureInfo("hr-HR");
else
newUICulture = new CultureInfo("sl-SI");
CultureInfo.CurrentUICulture = newUICulture;
Console.WriteLine("The current UI culture is now {0}",
CultureInfo.CurrentUICulture.Name);
}
}
// The example displays output like the following:
// The current UI culture is en-US
// The current UI culture is now sl-SI
Imports System.Globalization
Module Example
Public Sub Main()
Dim current As CultureInfo = CultureInfo.CurrentUICulture
Console.WriteLine("The current UI culture is {0}", current.Name)
Dim newUICulture As CultureInfo
If current.Name.Equals("sl-SI") Then
newUICulture = New CultureInfo("hr-HR")
Else
newUICulture = new CultureInfo("sl-SI")
End If
CultureInfo.CurrentUICulture = newUICulture
Console.WriteLine("The current UI culture is now {0}",
CultureInfo.CurrentUICulture.Name)
End Sub
End Module
' The example displays output like the following:
' The current UI culture is en-US
' The current UI culture is now sl-SI
모든 문화권 얻기
호출 하 여 로컬 컴퓨터에서 사용할 수 있는 모든 문화권 또는 문화권의 특정 범주 배열을 검색할 수 있습니다는 GetCultures 메서드. 예를 들어 사용자 지정 문화권, 특정 문화권 또는 중립 문화권은 단독으로 또는 함께 검색할 수 있습니다.
다음 예제에서는 GetCultures 메서드를 두 번 호출합니다. 먼저 System.Globalization.CultureTypes 열거형 멤버를 사용하여 모든 사용자 지정 문화권 검색을 한 System.Globalization.CultureTypes 다음, 열거형 멤버를 사용하여 모든 대체 문화권 검색을 수행합니다.
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
// Get all custom cultures.
CultureInfo[] custom = CultureInfo.GetCultures(CultureTypes.UserCustomCulture);
if (custom.Length == 0) {
Console.WriteLine("There are no user-defined custom cultures.");
}
else {
Console.WriteLine("Custom cultures:");
foreach (var culture in custom)
Console.WriteLine(" {0} -- {1}", culture.Name, culture.DisplayName);
}
Console.WriteLine();
// Get all replacement cultures.
CultureInfo[] replacements = CultureInfo.GetCultures(CultureTypes.ReplacementCultures);
if (replacements.Length == 0) {
Console.WriteLine("There are no replacement cultures.");
}
else {
Console.WriteLine("Replacement cultures:");
foreach (var culture in replacements)
Console.WriteLine(" {0} -- {1}", culture.Name, culture.DisplayName);
}
Console.WriteLine();
}
}
// The example displays output like the following:
// Custom cultures:
// x-en-US-sample -- English (United States)
// fj-FJ -- Boumaa Fijian (Viti)
//
// There are no replacement cultures.
Imports System.Globalization
Module Example
Public Sub Main()
' Get all custom cultures.
Dim custom() As CultureInfo = CultureInfo.GetCultures(CultureTypes.UserCustomCulture)
If custom.Length = 0 Then
Console.WriteLine("There are no user-defined custom cultures.")
Else
Console.WriteLine("Custom cultures:")
For Each culture In custom
Console.WriteLine(" {0} -- {1}", culture.Name, culture.DisplayName)
Next
End If
Console.WriteLine()
' Get all replacement cultures.
Dim replacements() As CultureInfo = CultureInfo.GetCultures(CultureTypes.ReplacementCultures)
If replacements.Length = 0 Then
Console.WriteLine("There are no replacement cultures.")
Else
Console.WriteLine("Replacement cultures:")
For Each culture in replacements
Console.WriteLine(" {0} -- {1}", culture.Name, culture.DisplayName)
Next
End If
Console.WriteLine()
End Sub
End Module
' The example displays output like the following:
' Custom cultures:
' x-en-US-sample -- English (United States)
' fj-FJ -- Boumaa Fijian (Viti)
'
' There are no replacement cultures.
문화권 및 스레드
새 애플리케이션 스레드가 시작 될 때 현재 문화권 및 현재 UI 문화권의 현재 스레드 문화권과 아니라에 현재 시스템 문화권에 의해 정의 됩니다. 다음 예제에서 차이점을 보여 줍니다. 프랑스어 (프랑스) 문화권 (FR) 애플리케이션 스레드의 현재 UI 문화권 및 현재 문화권으로 설정합니다. 현재 문화권이 이미 fr-FR인 경우 예제에서는 영어(미국) 문화권(en-US)으로 설정합니다. 세 개의 난수를 통화 값으로 표시한 다음 새 스레드를 만듭니다. 그러면 세 개의 난수를 통화 값으로 더 표시합니다. 하지만 새 스레드에 의해 표시 되는 통화 값은 예제에서에서 출력으로 기본 애플리케이션 스레드에서만에서 출력 달리 프랑스어 (프랑스) 문화권의 서식 규칙을 반영 하지 않습니다.
using System;
using System.Globalization;
using System.Threading;
public class Example
{
static Random rnd = new Random();
public static void Main()
{
if (Thread.CurrentThread.CurrentCulture.Name != "fr-FR") {
// If current culture is not fr-FR, set culture to fr-FR.
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR");
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR");
}
else {
// Set culture to en-US.
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("en-US");
}
ThreadProc();
Thread worker = new Thread(ThreadProc);
worker.Name = "WorkerThread";
worker.Start();
}
private static void DisplayThreadInfo()
{
Console.WriteLine("\nCurrent Thread Name: '{0}'",
Thread.CurrentThread.Name);
Console.WriteLine("Current Thread Culture/UI Culture: {0}/{1}",
Thread.CurrentThread.CurrentCulture.Name,
Thread.CurrentThread.CurrentUICulture.Name);
}
private static void DisplayValues()
{
// Create new thread and display three random numbers.
Console.WriteLine("Some currency values:");
for (int ctr = 0; ctr <= 3; ctr++)
Console.WriteLine(" {0:C2}", rnd.NextDouble() * 10);
}
private static void ThreadProc()
{
DisplayThreadInfo();
DisplayValues();
}
}
// The example displays output similar to the following:
// Current Thread Name: ''
// Current Thread Culture/UI Culture: fr-FR/fr-FR
// Some currency values:
// 8,11 €
// 1,48 €
// 8,99 €
// 9,04 €
//
// Current Thread Name: 'WorkerThread'
// Current Thread Culture/UI Culture: en-US/en-US
// Some currency values:
// $6.72
// $6.35
// $2.90
// $7.72
Imports System.Globalization
Imports System.Threading
Module Example
Dim rnd As New Random()
Public Sub Main()
If Thread.CurrentThread.CurrentCulture.Name <> "fr-FR" Then
' If current culture is not fr-FR, set culture to fr-FR.
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR")
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR")
Else
' Set culture to en-US.
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US")
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("en-US")
End If
ThreadProc()
Dim worker As New Thread(AddressOf ThreadProc)
worker.Name = "WorkerThread"
worker.Start()
End Sub
Private Sub DisplayThreadInfo()
Console.WriteLine()
Console.WriteLine("Current Thread Name: '{0}'",
Thread.CurrentThread.Name)
Console.WriteLine("Current Thread Culture/UI Culture: {0}/{1}",
Thread.CurrentThread.CurrentCulture.Name,
Thread.CurrentThread.CurrentUICulture.Name)
End Sub
Private Sub DisplayValues()
' Create new thread and display three random numbers.
Console.WriteLine("Some currency values:")
For ctr As Integer = 0 To 3
Console.WriteLine(" {0:C2}", rnd.NextDouble() * 10)
Next
End Sub
Private Sub ThreadProc()
DisplayThreadInfo()
DisplayValues()
End Sub
End Module
' The example displays output similar to the following:
' Current Thread Name: ''
' Current Thread Culture/UI Culture: fr-FR/fr-FR
' Some currency values:
' 8,11 €
' 1,48 €
' 8,99 €
' 9,04 €
'
' Current Thread Name: 'WorkerThread'
' Current Thread Culture/UI Culture: en-US/en-US
' Some currency values:
' $6.72
' $6.35
' $2.90
' $7.72
.NET Framework 4.5 이전의 .NET Framework 버전에서 주 애플리케이션 스레드가 다른 모든 작업자 스레드와 동일한 문화권을 공유하도록 하는 가장 일반적인 방법은 애플리케이션 전체 문화권의 이름 또는 CultureInfo 애플리케이션 전체 문화권을 나타내는 개체를 대리자에게 전달하는 System.Threading.ParameterizedThreadStart 것입니다. 다음 예제에서는 이 방법을 사용하여 두 스레드가 표시하는 통화 값이 동일한 문화권의 서식 규칙을 반영하도록 합니다.
using System;
using System.Globalization;
using System.Threading;
public class Example
{
static Random rnd = new Random();
public static void Main()
{
if (Thread.CurrentThread.CurrentCulture.Name != "fr-FR") {
// If current culture is not fr-FR, set culture to fr-FR.
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR");
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR");
}
else {
// Set culture to en-US.
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("en-US");
}
DisplayThreadInfo();
DisplayValues();
Thread worker = new Thread(Example.ThreadProc);
worker.Name = "WorkerThread";
worker.Start(Thread.CurrentThread.CurrentCulture);
}
private static void DisplayThreadInfo()
{
Console.WriteLine("\nCurrent Thread Name: '{0}'",
Thread.CurrentThread.Name);
Console.WriteLine("Current Thread Culture/UI Culture: {0}/{1}",
Thread.CurrentThread.CurrentCulture.Name,
Thread.CurrentThread.CurrentUICulture.Name);
}
private static void DisplayValues()
{
// Create new thread and display three random numbers.
Console.WriteLine("Some currency values:");
for (int ctr = 0; ctr <= 3; ctr++)
Console.WriteLine(" {0:C2}", rnd.NextDouble() * 10);
}
private static void ThreadProc(Object obj)
{
Thread.CurrentThread.CurrentCulture = (CultureInfo) obj;
Thread.CurrentThread.CurrentUICulture = (CultureInfo) obj;
DisplayThreadInfo();
DisplayValues();
}
}
// The example displays output similar to the following:
// Current Thread Name: ''
// Current Thread Culture/UI Culture: fr-FR/fr-FR
// Some currency values:
// 6,83 €
// 3,47 €
// 6,07 €
// 1,70 €
//
// Current Thread Name: 'WorkerThread'
// Current Thread Culture/UI Culture: fr-FR/fr-FR
// Some currency values:
// 9,54 €
// 9,50 €
// 0,58 €
// 6,91 €
Imports System.Globalization
Imports System.Threading
Module Example
Dim rnd As New Random()
Public Sub Main()
If Thread.CurrentThread.CurrentCulture.Name <> "fr-FR" Then
' If current culture is not fr-FR, set culture to fr-FR.
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR")
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR")
Else
' Set culture to en-US.
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US")
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("en-US")
End If
DisplayThreadInfo()
DisplayValues()
Dim worker As New Thread(AddressOf ThreadProc)
worker.Name = "WorkerThread"
worker.Start(Thread.CurrentThread.CurrentCulture)
End Sub
Private Sub DisplayThreadInfo()
Console.WriteLine()
Console.WriteLine("Current Thread Name: '{0}'",
Thread.CurrentThread.Name)
Console.WriteLine("Current Thread Culture/UI Culture: {0}/{1}",
Thread.CurrentThread.CurrentCulture.Name,
Thread.CurrentThread.CurrentUICulture.Name)
End Sub
Private Sub DisplayValues()
' Create new thread and display three random numbers.
Console.WriteLine("Some currency values:")
For ctr As Integer = 0 To 3
Console.WriteLine(" {0:C2}", rnd.NextDouble() * 10)
Next
End Sub
Private Sub ThreadProc(obj As Object)
Thread.CurrentThread.CurrentCulture = CType(obj, CultureInfo)
Thread.CurrentThread.CurrentUICulture = CType(obj, CultureInfo)
DisplayThreadInfo()
DisplayValues()
End Sub
End Module
' The example displays output similar to the following:
' Current Thread Name: ''
' Current Thread Culture/UI Culture: fr-FR/fr-FR
' Some currency values:
' 6,83 €
' 3,47 €
' 6,07 €
' 1,70 €
'
' Current Thread Name: 'WorkerThread'
' Current Thread Culture/UI Culture: fr-FR/fr-FR
' Some currency values:
' 9,54 €
' 9,50 €
' 0,58 €
' 6,91 €
메서드를 호출하여 비슷한 방식으로 스레드 풀 스레드의 문화권 및 UI 문화권 을 설정할 수 ThreadPool.QueueUserWorkItem(WaitCallback, Object) 있습니다.
.NET Framework 4.5부터 해당 문화권이 나타내는 개체를 및 속성에 할당하여 애플리케이션 도메인에 있는 모든 스레드의 문화권 및 UI 문화권 을 보다 직접적으로 설정할 수 CultureInfo DefaultThreadCurrentCulture DefaultThreadCurrentUICulture 있습니다. 다음 예제에서는 동일한 문화권을 공유 하는 기본 애플리케이션 도메인의 모든 스레드를 확인 하려면 이러한 속성을 사용 합니다.
using System;
using System.Globalization;
using System.Threading;
public class Example
{
static Random rnd = new Random();
public static void Main()
{
if (Thread.CurrentThread.CurrentCulture.Name != "fr-FR") {
// If current culture is not fr-FR, set culture to fr-FR.
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR");
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR");
}
else {
// Set culture to en-US.
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture("en-US");
}
ThreadProc();
Thread worker = new Thread(Example.ThreadProc);
worker.Name = "WorkerThread";
worker.Start();
}
private static void DisplayThreadInfo()
{
Console.WriteLine("\nCurrent Thread Name: '{0}'",
Thread.CurrentThread.Name);
Console.WriteLine("Current Thread Culture/UI Culture: {0}/{1}",
Thread.CurrentThread.CurrentCulture.Name,
Thread.CurrentThread.CurrentUICulture.Name);
}
private static void DisplayValues()
{
// Create new thread and display three random numbers.
Console.WriteLine("Some currency values:");
for (int ctr = 0; ctr <= 3; ctr++)
Console.WriteLine(" {0:C2}", rnd.NextDouble() * 10);
}
private static void ThreadProc()
{
DisplayThreadInfo();
DisplayValues();
}
}
// The example displays output similar to the following:
// Current Thread Name: ''
// Current Thread Culture/UI Culture: fr-FR/fr-FR
// Some currency values:
// 6,83 €
// 3,47 €
// 6,07 €
// 1,70 €
//
// Current Thread Name: 'WorkerThread'
// Current Thread Culture/UI Culture: fr-FR/fr-FR
// Some currency values:
// 9,54 €
// 9,50 €
// 0,58 €
// 6,91 €
Imports System.Globalization
Imports System.Threading
Module Example
Dim rnd As New Random()
Public Sub Main()
If Thread.CurrentThread.CurrentCulture.Name <> "fr-FR" Then
' If current culture is not fr-FR, set culture to fr-FR.
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR")
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR")
Else
' Set culture to en-US.
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("en-US")
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture("en-US")
End If
ThreadProc()
Dim worker As New Thread(AddressOf ThreadProc)
worker.Name = "WorkerThread"
worker.Start()
End Sub
Private Sub DisplayThreadInfo()
Console.WriteLine()
Console.WriteLine("Current Thread Name: '{0}'",
Thread.CurrentThread.Name)
Console.WriteLine("Current Thread Culture/UI Culture: {0}/{1}",
Thread.CurrentThread.CurrentCulture.Name,
Thread.CurrentThread.CurrentUICulture.Name)
End Sub
Private Sub DisplayValues()
' Create new thread and display three random numbers.
Console.WriteLine("Some currency values:")
For ctr As Integer = 0 To 3
Console.WriteLine(" {0:C2}", rnd.NextDouble() * 10)
Next
End Sub
Private Sub ThreadProc()
DisplayThreadInfo()
DisplayValues()
End Sub
End Module
' The example displays output similar to the following:
' Current Thread Name: ''
' Current Thread Culture/UI Culture: fr-FR/fr-FR
' Some currency values:
' 6,83 €
' 3,47 €
' 6,07 €
' 1,70 €
'
' Current Thread Name: 'WorkerThread'
' Current Thread Culture/UI Culture: fr-FR/fr-FR
' Some currency values:
' 9,54 €
' 9,50 €
' 0,58 €
' 6,91 €
경고
하지만 합니다 DefaultThreadCurrentCulture 및 DefaultThreadCurrentUICulture 속성은 정적 멤버를 기본 문화권 및 이러한 속성 값이 설정 된 당시에는 애플리케이션 도메인에 대해서만 기본 UI 문화권을 정의 합니다. 자세한 내용은 다음 섹션을 참조 하세요 문화권 및 애플리케이션 도메인합니다.
값을 할당 하는 경우는 DefaultThreadCurrentCulture 고 DefaultThreadCurrentUICulture 속성, 문화권 및 UI 문화권 애플리케이션 도메인에 있는 스레드의 경우 변경할 수도 있습니다 명시적으로 할당 하지 않은 문화권입니다. 그러나 이러한 스레드는 현재 애플리케이션 도메인에서 실행 하는 동안에 새 culture 설정을 반영 합니다. 이러한 스레드를 다른 애플리케이션 도메인에서 실행 하는 경우 해당 문화권에 해당 애플리케이션 도메인에 대해 정의 된 기본 문화권이 됩니다. 결과적으로, 것이 좋습니다에 의존 하지 않고 항상 주 애플리케이션 스레드의 문화권을 설정 하는 DefaultThreadCurrentCulture 및 DefaultThreadCurrentUICulture 속성을 변경 합니다.
문화권 및 애플리케이션 도메인
DefaultThreadCurrentCulture 및 DefaultThreadCurrentUICulture 하는 속성 값을 설정 하거나 검색할 때 현재 애플리케이션 도메인에 대해서만 기본 문화권을 명시적으로 정의 하는 정적 속성입니다. 다음 예제에서는 기본 애플리케이션 도메인에서 기본 문화권 및 기본 UI 문화권을 프랑스어 (프랑스)로 설정 하 고 사용 하 여는 AppDomainSetup 클래스 및 AppDomainInitializer 대리자가 새 애플리케이션 도메인을의 기본 문화권 및 UI 문화권 설정 러시아어 (러시아)입니다. 그런 다음 단일 스레드는 각 애플리케이션 도메인에서 두 메서드를 실행합니다. Note는 스레드의 문화권과 UI 문화권은 명시적으로 설정 하지; 기본 문화권 및 UI 문화권은 스레드가 실행 중인 애플리케이션 도메인에서 파생 됩니다. 또한 합니다 DefaultThreadCurrentCulture 하 고 DefaultThreadCurrentUICulture 속성 기본값을 반환 CultureInfo 메서드를 호출 하는 경우 현재 애플리케이션 도메인의 값입니다.
using System;
using System.Globalization;
using System.Reflection;
using System.Threading;
public class Example
{
public static void Main()
{
// Set the default culture and display the current date in the current application domain.
Info info1 = new Info();
SetAppDomainCultures("fr-FR");
// Create a second application domain.
AppDomainSetup setup = new AppDomainSetup();
setup.AppDomainInitializer = SetAppDomainCultures;
setup.AppDomainInitializerArguments = new string[] { "ru-RU" };
AppDomain domain = AppDomain.CreateDomain("Domain2", null, setup);
// Create an Info object in the new application domain.
Info info2 = (Info) domain.CreateInstanceAndUnwrap(typeof(Example).Assembly.FullName,
"Info");
// Execute methods in the two application domains.
info2.DisplayDate();
info2.DisplayCultures();
info1.DisplayDate();
info1.DisplayCultures();
}
public static void SetAppDomainCultures(string[] names)
{
SetAppDomainCultures(names[0]);
}
public static void SetAppDomainCultures(string name)
{
try {
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture(name);
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture(name);
}
// If an exception occurs, we'll just fall back to the system default.
catch (CultureNotFoundException) {
return;
}
catch (ArgumentException) {
return;
}
}
}
public class Info : MarshalByRefObject
{
public void DisplayDate()
{
Console.WriteLine("Today is {0:D}", DateTime.Now);
}
public void DisplayCultures()
{
Console.WriteLine("Application domain is {0}", AppDomain.CurrentDomain.Id);
Console.WriteLine("Default Culture: {0}", CultureInfo.DefaultThreadCurrentCulture);
Console.WriteLine("Default UI Culture: {0}", CultureInfo.DefaultThreadCurrentUICulture);
}
}
// The example displays the following output:
// Today is 14 октября 2011 г.
// Application domain is 2
// Default Culture: ru-RU
// Default UI Culture: ru-RU
// Today is vendredi 14 octobre 2011
// Application domain is 1
// Default Culture: fr-FR
// Default UI Culture: fr-FR
Imports System.Globalization
Imports System.Reflection
Imports System.Threading
Module Example
Public Sub Main()
' Set the default culture and display the current date in the current application domain.
Dim info1 As New Info()
SetAppDomainCultures("fr-FR")
' Create a second application domain.
Dim setup As New AppDomainSetup()
setup.AppDomainInitializer = AddressOf SetAppDomainCultures
setup.AppDomainInitializerArguments = { "ru-RU" }
Dim domain As AppDomain = AppDomain.CreateDomain("Domain2", Nothing, setup)
' Create an Info object in the new application domain.
Dim info2 As Info = CType(domain.CreateInstanceAndUnwrap(GetType(Example).Assembly.FullName,
"Info"), Info)
' Execute methods in the two application domains.
info2.DisplayDate()
info2.DisplayCultures()
info1.DisplayDate()
info1.DisplayCultures()
End Sub
Public Sub SetAppDomainCultures(names() As String)
SetAppDomainCultures(names(0))
End Sub
Public Sub SetAppDomainCultures(name As String)
Try
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture(name)
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture(name)
' If an exception occurs, we'll just fall back to the system default.
Catch e As CultureNotFoundException
Return
Catch e As ArgumentException
Return
End Try
End Sub
End Module
Public Class Info : Inherits MarshalByRefObject
Public Sub DisplayDate()
Console.WriteLine("Today is {0:D}", Date.Now)
End Sub
Public Sub DisplayCultures()
Console.WriteLine("Application domain is {0}", AppDomain.CurrentDomain.Id)
Console.WriteLine("Default Culture: {0}", CultureInfo.DefaultThreadCurrentCulture)
Console.WriteLine("Default UI Culture: {0}", CultureInfo.DefaultThreadCurrentUICulture)
End Sub
End Class
' The example displays the following output:
' Today is 14 октября 2011 г.
' Application domain is 2
' Default Culture: ru-RU
' Default UI Culture: ru-RU
' Today is vendredi 14 octobre 2011
' Application domain is 1
' Default Culture: fr-FR
' Default UI Culture: fr-FR
문화권 및 애플리케이션 도메인에 대한 자세한 내용은 애플리케이션 도메인 항목의 "애플리케이션 도메인 및 스레드" 섹션을 참조하세요.
문화권 및 작업 기반 비동기 작업
작업 기반 비동기 프로그래밍 패턴은 Task 및 개체를 사용하여 스레드 풀 Task<TResult> 스레드에서 대리자를 비동기적으로 실행합니다. 특정 태스크가 실행되는 특정 스레드는 사전에 알려지지 않지만 런타임에만 결정됩니다.
.NET Framework 4.6 이상 버전을 대상으로 하는 앱의 경우 culture는 비동기 작업 컨텍스트의 일부입니다. 즉, .NET Framework 4.6을 대상으로 하는 앱부터 비동기 작업은 기본적으로 CurrentCulture 시작되는 스레드의 및 속성 값을 CurrentUICulture 상속합니다. 현재 문화권 또는 현재 UI 문화권이 시스템 문화권과 다른 경우 현재 문화권은 스레드 경계를 넘어 비동기 작업을 실행하는 스레드 풀 스레드의 현재 문화권이 됩니다.
다음 예제에서는 간단한 설명을 제공합니다. 특성을 사용하여 TargetFrameworkAttribute .NET Framework 4.6을 대상으로 지정합니다. 이 예제에서는 Func<TResult> 통화 값으로 서식이 지정된 일부 숫자를 반환하는 대리자 를 formatDelegate 정의합니다. 이 예제에서는 현재 시스템 문화권이 프랑스어(프랑스) 또는 프랑스어(프랑스)가 이미 현재 문화권인 경우 영어(미국)로 변경합니다. 그런 다음, 다음을 수행합니다.
기본 앱 스레드에서 동기적으로 실행되도록 대리자를 직접 호출합니다.
스레드 풀 스레드에서 대리자를 비동기적으로 실행하는 작업을 만듭니다.
메서드를 호출하여 주 앱 스레드에서 대리자를 동기적으로 실행하는 작업을 Task.RunSynchronously 만듭니다.
예제의 출력과 같이 현재 문화권이 프랑스어(프랑스)로 변경되면 작업이 비동기적으로 호출되는 스레드의 현재 문화권이 해당 비동기 작업의 현재 문화권이 됩니다.
using System;
using System.Globalization;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
[assembly:TargetFramework(".NETFramework,Version=v4.6")]
public class Example
{
public static void Main()
{
decimal[] values = { 163025412.32m, 18905365.59m };
string formatString = "C2";
Func<String> formatDelegate = () => { string output = String.Format("Formatting using the {0} culture on thread {1}.\n",
CultureInfo.CurrentCulture.Name,
Thread.CurrentThread.ManagedThreadId);
foreach (var value in values)
output += String.Format("{0} ", value.ToString(formatString));
output += Environment.NewLine;
return output;
};
Console.WriteLine("The example is running on thread {0}",
Thread.CurrentThread.ManagedThreadId);
// Make the current culture different from the system culture.
Console.WriteLine("The current culture is {0}",
CultureInfo.CurrentCulture.Name);
if (CultureInfo.CurrentCulture.Name == "fr-FR")
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
else
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
Console.WriteLine("Changed the current culture to {0}.\n",
CultureInfo.CurrentCulture.Name);
// Execute the delegate synchronously.
Console.WriteLine("Executing the delegate synchronously:");
Console.WriteLine(formatDelegate());
// Call an async delegate to format the values using one format string.
Console.WriteLine("Executing a task asynchronously:");
var t1 = Task.Run(formatDelegate);
Console.WriteLine(t1.Result);
Console.WriteLine("Executing a task synchronously:");
var t2 = new Task<String>(formatDelegate);
t2.RunSynchronously();
Console.WriteLine(t2.Result);
}
}
// The example displays the following output:
// The example is running on thread 1
// The current culture is en-US
// Changed the current culture to fr-FR.
//
// Executing the delegate synchronously:
// Formatting using the fr-FR culture on thread 1.
// 163 025 412,32 € 18 905 365,59 €
//
// Executing a task asynchronously:
// Formatting using the fr-FR culture on thread 3.
// 163 025 412,32 € 18 905 365,59 €
//
// Executing a task synchronously:
// Formatting using the fr-FR culture on thread 1.
// 163 025 412,32 € 18 905 365,59 €
Imports System.Globalization
Imports System.Runtime.Versioning
Imports System.Threading
Imports System.Threading.Tasks
<Assembly:TargetFramework(".NETFramework,Version=v4.6")>
Module Example
Public Sub Main()
Dim values() As Decimal = { 163025412.32d, 18905365.59d }
Dim formatString As String = "C2"
Dim formatDelegate As Func(Of String) = Function()
Dim output As String = String.Format("Formatting using the {0} culture on thread {1}.",
CultureInfo.CurrentCulture.Name,
Thread.CurrentThread.ManagedThreadId)
output += Environment.NewLine
For Each value In values
output += String.Format("{0} ", value.ToString(formatString))
Next
output += Environment.NewLine
Return output
End Function
Console.WriteLine("The example is running on thread {0}",
Thread.CurrentThread.ManagedThreadId)
' Make the current culture different from the system culture.
Console.WriteLine("The current culture is {0}",
CultureInfo.CurrentCulture.Name)
If CultureInfo.CurrentCulture.Name = "fr-FR" Then
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US")
Else
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR")
End If
Console.WriteLine("Changed the current culture to {0}.",
CultureInfo.CurrentCulture.Name)
Console.WriteLine()
' Execute the delegate synchronously.
Console.WriteLine("Executing the delegate synchronously:")
Console.WriteLine(formatDelegate())
' Call an async delegate to format the values using one format string.
Console.WriteLine("Executing a task asynchronously:")
Dim t1 = Task.Run(formatDelegate)
Console.WriteLine(t1.Result)
Console.WriteLine("Executing a task synchronously:")
Dim t2 = New Task(Of String)(formatDelegate)
t2.RunSynchronously()
Console.WriteLine(t2.Result)
End Sub
End Module
' The example displays the following output:
' The example is running on thread 1
' The current culture is en-US
' Changed the current culture to fr-FR.
'
' Executing the delegate synchronously:
' Formatting Imports the fr-FR culture on thread 1.
' 163 025 412,32 € 18 905 365,59 €
'
' Executing a task asynchronously:
' Formatting Imports the fr-FR culture on thread 3.
' 163 025 412,32 € 18 905 365,59 €
'
' Executing a task synchronously:
' Formatting Imports the fr-FR culture on thread 1.
' 163 025 412,32 € 18 905 365,59 €
.NET Framework 4.6 이전의 .NET Framework 버전을 대상으로 하는 앱 또는 특정 버전의 .NET Framework 대상으로 하지 않는 앱의 경우 호출 스레드의 문화권은 작업 컨텍스트의 일부가 아닙니다. 대신 명시적으로 정의되지 않는 한 기본적으로 새 스레드의 문화권은 시스템 문화권입니다. 특성이 없다는 점을 제외하고 이전 예제와 동일한 다음 예제는 TargetFrameworkAttribute 이를 보여 줍니다. 예제가 실행된 시스템의 시스템 문화권이 영어(미국)이므로 스레드 풀 스레드에서 비동기적으로 실행되는 작업의 문화권은 en-US 가 아닌 fr-FR 입니다.
using System;
using System.Globalization;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
public class Example
{
public static void Main()
{
decimal[] values = { 163025412.32m, 18905365.59m };
string formatString = "C2";
Func<String> formatDelegate = () => { string output = String.Format("Formatting using the {0} culture on thread {1}.\n",
CultureInfo.CurrentCulture.Name,
Thread.CurrentThread.ManagedThreadId);
foreach (var value in values)
output += String.Format("{0} ", value.ToString(formatString));
output += Environment.NewLine;
return output;
};
Console.WriteLine("The example is running on thread {0}",
Thread.CurrentThread.ManagedThreadId);
// Make the current culture different from the system culture.
Console.WriteLine("The current culture is {0}",
CultureInfo.CurrentCulture.Name);
if (CultureInfo.CurrentCulture.Name == "fr-FR")
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
else
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
Console.WriteLine("Changed the current culture to {0}.\n",
CultureInfo.CurrentCulture.Name);
// Execute the delegate synchronously.
Console.WriteLine("Executing the delegate synchronously:");
Console.WriteLine(formatDelegate());
// Call an async delegate to format the values using one format string.
Console.WriteLine("Executing a task asynchronously:");
var t1 = Task.Run(formatDelegate);
Console.WriteLine(t1.Result);
Console.WriteLine("Executing a task synchronously:");
var t2 = new Task<String>(formatDelegate);
t2.RunSynchronously();
Console.WriteLine(t2.Result);
}
}
// The example displays the following output:
// The example is running on thread 1
// The current culture is en-US
// Changed the current culture to fr-FR.
//
// Executing the delegate synchronously:
// Formatting using the fr-FR culture on thread 1.
// 163 025 412,32 € 18 905 365,59 €
//
// Executing a task asynchronously:
// Formatting using the en-US culture on thread 3.
// $163,025,412.32 $18,905,365.59
//
// Executing a task synchronously:
// Formatting using the fr-FR culture on thread 1.
// 163 025 412,32 € 18 905 365,59 €
Imports System.Globalization
Imports System.Runtime.Versioning
Imports System.Threading
Imports System.Threading.Tasks
Module Example
Public Sub Main()
Dim values() As Decimal = { 163025412.32d, 18905365.59d }
Dim formatString As String = "C2"
Dim formatDelegate As Func(Of String) = Function()
Dim output As String = String.Format("Formatting using the {0} culture on thread {1}.",
CultureInfo.CurrentCulture.Name,
Thread.CurrentThread.ManagedThreadId)
output += Environment.NewLine
For Each value In values
output += String.Format("{0} ", value.ToString(formatString))
Next
output += Environment.NewLine
Return output
End Function
Console.WriteLine("The example is running on thread {0}",
Thread.CurrentThread.ManagedThreadId)
' Make the current culture different from the system culture.
Console.WriteLine("The current culture is {0}",
CultureInfo.CurrentCulture.Name)
If CultureInfo.CurrentCulture.Name = "fr-FR" Then
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US")
Else
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR")
End If
Console.WriteLine("Changed the current culture to {0}.",
CultureInfo.CurrentCulture.Name)
Console.WriteLine()
' Execute the delegate synchronously.
Console.WriteLine("Executing the delegate synchronously:")
Console.WriteLine(formatDelegate())
' Call an async delegate to format the values using one format string.
Console.WriteLine("Executing a task asynchronously:")
Dim t1 = Task.Run(formatDelegate)
Console.WriteLine(t1.Result)
Console.WriteLine("Executing a task synchronously:")
Dim t2 = New Task(Of String)(formatDelegate)
t2.RunSynchronously()
Console.WriteLine(t2.Result)
End Sub
End Module
' The example displays the following output:
' The example is running on thread 1
' The current culture is en-US
' Changed the current culture to fr-FR.
'
' Executing the delegate synchronously:
' Formatting using the fr-FR culture on thread 1.
' 163 025 412,32 € 18 905 365,59 €
'
' Executing a task asynchronously:
' Formatting using the en-US culture on thread 3.
' $163,025,412.32 $18,905,365.59
'
' Executing a task synchronously:
' Formatting using the fr-FR culture on thread 1.
' 163 025 412,32 € 18 905 365,59 €
.NET Framework 4.5 이상에서 .NET Framework 4.6 이전의 .NET Framework 버전을 대상으로 하는 앱의 경우 및 속성을 사용하여 DefaultThreadCurrentCulture DefaultThreadCurrentUICulture 스레드 풀 스레드에서 실행되는 비동기 작업에서 호출 스레드의 문화권이 사용되도록 할 수 있습니다. 다음 예제는 이전 예제와 동일합니다. 단, 속성을 사용하여 DefaultThreadCurrentCulture 스레드 풀 스레드가 주 앱 스레드와 동일한 문화권을 갖도록 합니다.
using System;
using System.Globalization;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
public class Example
{
public static void Main()
{
decimal[] values = { 163025412.32m, 18905365.59m };
string formatString = "C2";
Func<String> formatDelegate = () => { string output = String.Format("Formatting using the {0} culture on thread {1}.\n",
CultureInfo.CurrentCulture.Name,
Thread.CurrentThread.ManagedThreadId);
foreach (var value in values)
output += String.Format("{0} ", value.ToString(formatString));
output += Environment.NewLine;
return output;
};
Console.WriteLine("The example is running on thread {0}",
Thread.CurrentThread.ManagedThreadId);
// Make the current culture different from the system culture.
Console.WriteLine("The current culture is {0}",
CultureInfo.CurrentCulture.Name);
if (CultureInfo.CurrentCulture.Name == "fr-FR")
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
else
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
Console.WriteLine("Changed the current culture to {0}.\n",
CultureInfo.CurrentCulture.Name);
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CurrentCulture;
// Execute the delegate synchronously.
Console.WriteLine("Executing the delegate synchronously:");
Console.WriteLine(formatDelegate());
// Call an async delegate to format the values using one format string.
Console.WriteLine("Executing a task asynchronously:");
var t1 = Task.Run(formatDelegate);
Console.WriteLine(t1.Result);
Console.WriteLine("Executing a task synchronously:");
var t2 = new Task<String>(formatDelegate);
t2.RunSynchronously();
Console.WriteLine(t2.Result);
}
}
// The example displays the following output:
// The example is running on thread 1
// The current culture is en-US
// Changed the current culture to fr-FR.
//
// Executing the delegate synchronously:
// Formatting using the fr-FR culture on thread 1.
// 163 025 412,32 € 18 905 365,59 €
//
// Executing a task asynchronously:
// Formatting using the fr-FR culture on thread 3.
// 163 025 412,32 € 18 905 365,59 €
//
// Executing a task synchronously:
// Formatting using the fr-FR culture on thread 1.
// 163 025 412,32 € 18 905 365,59 €
Imports System.Globalization
Imports System.Runtime.Versioning
Imports System.Threading
Imports System.Threading.Tasks
Module Example
Public Sub Main()
Dim values() As Decimal = { 163025412.32d, 18905365.59d }
Dim formatString As String = "C2"
Dim formatDelegate As Func(Of String) = Function()
Dim output As String = String.Format("Formatting using the {0} culture on thread {1}.",
CultureInfo.CurrentCulture.Name,
Thread.CurrentThread.ManagedThreadId)
output += Environment.NewLine
For Each value In values
output += String.Format("{0} ", value.ToString(formatString))
Next
output += Environment.NewLine
Return output
End Function
Console.WriteLine("The example is running on thread {0}",
Thread.CurrentThread.ManagedThreadId)
' Make the current culture different from the system culture.
Console.WriteLine("The current culture is {0}",
CultureInfo.CurrentCulture.Name)
If CultureInfo.CurrentCulture.Name = "fr-FR" Then
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US")
Else
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR")
End If
Console.WriteLine("Changed the current culture to {0}.",
CultureInfo.CurrentCulture.Name)
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CurrentCulture
Console.WriteLine()
' Execute the delegate synchronously.
Console.WriteLine("Executing the delegate synchronously:")
Console.WriteLine(formatDelegate())
' Call an async delegate to format the values using one format string.
Console.WriteLine("Executing a task asynchronously:")
Dim t1 = Task.Run(formatDelegate)
Console.WriteLine(t1.Result)
Console.WriteLine("Executing a task synchronously:")
Dim t2 = New Task(Of String)(formatDelegate)
t2.RunSynchronously()
Console.WriteLine(t2.Result)
End Sub
End Module
' The example displays the following output:
' The example is running on thread 1
' The current culture is en-US
' Changed the current culture to fr-FR.
'
' Executing the delegate synchronously:
' Formatting using the fr-FR culture on thread 1.
' 163 025 412,32 € 18 905 365,59 €
'
' Executing a task asynchronously:
' Formatting using the fr-FR culture on thread 3.
' 163 025 412,32 € 18 905 365,59 €
'
' Executing a task synchronously:
' Formatting using the fr-FR culture on thread 1.
' 163 025 412,32 € 18 905 365,59 €
DefaultThreadCurrentCulture 및 DefaultThreadCurrentUICulture 앱 별 도메인 속성은 모든 스레드는 특정 애플리케이션 도메인에서 문화권을 명시적으로 할당에 대 한 기본 문화권 설정 즉, 합니다. 그러나 .NET Framework 4.6 이상 을 대상으로 하는 앱의 경우 작업이 앱 도메인 경계를 넘어가더라도 호출 스레드의 문화권은 비동기 작업 컨텍스트의 일부로 유지됩니다.
다음 예제는 호출 스레드의 문화권은 작업이 실행 되는 메서드를 애플리케이션 도메인 경계를 넘는 경우에 작업 기반 비동기 작업의 현재 문화권을 유지 하는 것입니다. 단일 메서드 를 사용하여 DataRetriever GetFormattedNumber 1에서 1,000 사이의 임의의 배정밀도 부동 소수점 숫자를 통화 값으로 반환하는 클래스를 정의합니다. 인스턴스를 인스턴스화하고 해당 메서드를 호출하는 첫 번째 작업이 DataRetriever GetFormattedNumber 실행됩니다. 현재 애플리케이션 도메인을 보고, 새 애플리케이션 도메인을 만듭니다, 인스턴스화하는 두 번째 작업을 DataRetriever 새 애플리케이션 도메인 및 호출의 인스턴스에 해당 GetFormattedNumber 메서드. 예제의 출력에서 볼 수 있듯이 현재 문화권에 동일 하 게 호출 스레드, 첫 번째 작업에서는 및 두 번째 태스크는 모두 기본 애플리케이션 도메인 및 두 번째 애플리케이션 도메인에서 실행 될 때입니다.
using System;
using System.Globalization;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
[assembly:TargetFramework(".NETFramework,Version=v4.6")]
public class Example
{
public static void Main()
{
string formatString = "C2";
Console.WriteLine("The example is running on thread {0}",
Thread.CurrentThread.ManagedThreadId);
// Make the current culture different from the system culture.
Console.WriteLine("The current culture is {0}",
CultureInfo.CurrentCulture.Name);
if (CultureInfo.CurrentCulture.Name == "fr-FR")
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
else
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
Console.WriteLine("Changed the current culture to {0}.\n",
CultureInfo.CurrentCulture.Name);
// Call an async delegate to format the values using one format string.
Console.WriteLine("Executing a task asynchronously in the main appdomain:");
var t1 = Task.Run(() => { DataRetriever d = new DataRetriever();
return d.GetFormattedNumber(formatString);
});
Console.WriteLine(t1.Result);
Console.WriteLine();
Console.WriteLine("Executing a task synchronously in two appdomains:");
var t2 = Task.Run(() => { Console.WriteLine("Thread {0} is running in app domain '{1}'",
Thread.CurrentThread.ManagedThreadId,
AppDomain.CurrentDomain.FriendlyName);
AppDomain domain = AppDomain.CreateDomain("Domain2");
DataRetriever d = (DataRetriever) domain.CreateInstanceAndUnwrap(typeof(Example).Assembly.FullName,
"DataRetriever");
return d.GetFormattedNumber(formatString);
});
Console.WriteLine(t2.Result);
}
}
public class DataRetriever : MarshalByRefObject
{
public string GetFormattedNumber(String format)
{
Thread thread = Thread.CurrentThread;
Console.WriteLine("Current culture is {0}", thread.CurrentCulture);
Console.WriteLine("Thread {0} is running in app domain '{1}'",
thread.ManagedThreadId,
AppDomain.CurrentDomain.FriendlyName);
Random rnd = new Random();
Double value = rnd.NextDouble() * 1000;
return value.ToString(format);
}
}
// The example displays output like the following:
// The example is running on thread 1
// The current culture is en-US
// Changed the current culture to fr-FR.
//
// Executing a task asynchronously in a single appdomain:
// Current culture is fr-FR
// Thread 3 is running in app domain 'AsyncCulture4.exe'
// 93,48 €
//
// Executing a task synchronously in two appdomains:
// Thread 4 is running in app domain 'AsyncCulture4.exe'
// Current culture is fr-FR
// Thread 4 is running in app domain 'Domain2'
// 288,66 €
Imports System.Globalization
Imports System.Runtime.Versioning
Imports System.Threading
Imports System.Threading.Tasks
<Assembly:TargetFramework(".NETFramework,Version=v4.6")>
Module Example
Public Sub Main()
Dim formatString As String = "C2"
Console.WriteLine("The example is running on thread {0}",
Thread.CurrentThread.ManagedThreadId)
' Make the current culture different from the system culture.
Console.WriteLine("The current culture is {0}",
CultureInfo.CurrentCulture.Name)
If CultureInfo.CurrentCulture.Name = "fr-FR" Then
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US")
Else
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR")
End If
Console.WriteLine("Changed the current culture to {0}.",
CultureInfo.CurrentCulture.Name)
Console.WriteLine()
' Call an async delegate to format the values using one format string.
Console.WriteLine("Executing a task asynchronously in the main appdomain:")
Dim t1 = Task.Run(Function()
Dim d As New DataRetriever()
Return d.GetFormattedNumber(formatString)
End Function)
Console.WriteLine(t1.Result)
Console.WriteLine()
Console.WriteLine("Executing a task synchronously in two appdomains:")
Dim t2 = Task.Run(Function()
Console.WriteLine("Thread {0} is running in app domain '{1}'",
Thread.CurrentThread.ManagedThreadId,
AppDomain.CurrentDomain.FriendlyName)
Dim domain As AppDomain = AppDomain.CreateDomain("Domain2")
Dim d As DataRetriever = CType(domain.CreateInstanceAndUnwrap(GetType(Example).Assembly.FullName,
"DataRetriever"), DataRetriever)
Return d.GetFormattedNumber(formatString)
End Function)
Console.WriteLine(t2.Result)
End Sub
End Module
Public Class DataRetriever : Inherits MarshalByRefObject
Public Function GetFormattedNumber(format As String) As String
Dim thread As Thread = Thread.CurrentThread
Console.WriteLine("Current culture is {0}", thread.CurrentCulture)
Console.WriteLine("Thread {0} is running in app domain '{1}'",
thread.ManagedThreadId,
AppDomain.CurrentDomain.FriendlyName)
Dim rnd As New Random()
Dim value As Double = rnd.NextDouble() * 1000
Return value.ToString(format)
End Function
End Class
' The example displays output like the following:
' The example is running on thread 1
' The current culture is en-US
' Changed the current culture to fr-FR.
'
' Executing a task asynchronously in a single appdomain:
' Current culture is fr-FR
' Thread 3 is running in app domain 'AsyncCulture4.exe'
' 93,48 €
'
' Executing a task synchronously in two appdomains:
' Thread 4 is running in app domain 'AsyncCulture4.exe'
' Current culture is fr-FR
' Thread 4 is running in app domain 'Domain2'
' 288,66 €
CultureInfo 개체 serialization
CultureInfo개체가 serialized되면 실제로 저장되는 것은 Name 및 UseUserOverride 입니다. 동일한 의미를 가지는 환경에서만 성공적으로 deserialized됩니다. Name 다음 세 가지 예제에서는 이것이 항상 그렇지 않은 이유를 보여 제공합니다.
속성 CultureTypes 값이 CultureTypes.InstalledWin32Cultures 이고 해당 문화권이 Windows 운영 체제의 특정 버전에서 처음 도입된 경우 이전 버전의 Windows 이 문화권을 deserialize할 수 없습니다. 예를 들어 Windows 10 문화권이 도입된 경우 Windows 8 문화권은 deserialized할 수 없습니다.
CultureTypes값이 CultureTypes.UserCustomCulture 이고 이 값이 deserialize된 컴퓨터에 이 사용자 지정 문화권이 설치되어 있지 않으면 해당 문화권은 deserialize할 수 없습니다.
CultureTypes값이 이고 이 CultureTypes.ReplacementCultures 값이 deserialize된 컴퓨터에 이 대체 문화권이 없으면 동일한 이름으로 deserialize되지만 모두 동일한 특성은 아닙니다. 예를 들어 가
en-US컴퓨터 A의 대체 문화권이지만 컴퓨터 B에는 없는 경우 및 CultureInfo 이 문화권에 참조하는 개체가 컴퓨터 A에서 직렬화되고 컴퓨터 B에서 deserialized되는 경우 문화권의 사용자 지정 특성은 전송되지 않습니다. 문화권은 성공적으로 deserialize되지만 의미는 다릅니다.
제어판 재정의
사용자는 제어판 지역 및 언어 옵션 부분을 통해 Windows 현재 문화권과 연결된 일부 값을 재정의하도록 선택할 수 있습니다. 예를 들어 사용자는 다른 형식으로 날짜를 표시하거나 문화권의 기본값이 아닌 다른 통화를 사용하도록 선택할 수 있습니다. 일반적으로 애플리케이션 사용자 재정의 적용 해야 합니다.
경우 UseUserOverride 는 및 지정 된 true 문화권의 현재 문화권과 일치 Windows, 속성에서 반환 하는 CultureInfo 인스턴스의 속성에 대 한 사용자 설정을 포함 하 여 이러한 재정의 사용 합니다 DateTimeFormatInfo 속성 및 DateTimeFormat NumberFormatInfo 속성에서 반환 하는 인스턴스의 NumberFormat 속성입니다. 사용자 설정이 와 연결된 문화권과 호환되지 CultureInfo 않는 경우(예: 선택한 달력이 중 하나가 아닌 OptionalCalendars 경우) 메서드의 결과와 속성 값이 정의되지 않습니다.
대체 정렬 순서
일부 문화권은 두 개 이상의 정렬 순서를 지원합니다. 예를 들면 다음과 같습니다.
스페인어(스페인) 문화권에는 기본 국제 정렬 순서와 기존 정렬 순서의 두 가지 정렬 순서가 있습니다. 문화권 이름을 사용하여 개체를 인스턴스화하면 CultureInfo
es-ES국제 정렬 순서가 사용됩니다. 문화권 이름을 사용하여 개체를 인스턴스화하면 CultureInfoes-ES-tradnl기존 정렬 순서가 사용됩니다.zh-CN(중국어(간체, PRC)) 문화권은 발음(기본값) 및 스트로크 수의 두 가지 정렬 순서를 지원합니다. 문화권 이름을 사용하여 개체를 인스턴스화하면 CultureInfozh-CN기본 정렬 순서가 사용됩니다. 0x00020804 로컬 식별자를 가진 개체를 인스턴스화하면 CultureInfo 문자열이 스트로크 수별로 정렬됩니다.
다음 표에서는 대체 정렬 순서를 지원하는 문화권과 기본 및 대체 정렬 순서에 대한 식별자를 나열합니다.
| 문화권 이름 | 문화권 | 기본 정렬 이름 및 식별자 | 대체 정렬 이름 및 식별자 |
|---|---|---|---|
| es-ES | 스페인어(스페인) | 국제: 0x00000C0A | 기존: 0x0000040A |
| zh-TW | 중국어(대만) | 스트로크 수: 0x00000404 | Bopomofo: 0x00030404 |
| zh-CN | 중국어(중국) | 발음: 0x00000804 | 스트로크 수: 0x00020804 |
| zh-HK | 중국어(홍콩 특별 행정구) | 스트로크 수: 0x00000c04 | 스트로크 수: 0x00020c04 |
| zh-SG | 중국어(싱가포르) | 발음: 0x00001004 | 스트로크 수: 0x00021004 |
| zh-MO | 중국어(마카오 특별 행정구) | 발음: 0x00001404 | 스트로크 수: 0x00021404 |
| ja-JP | 일본어(일본) | 기본값: 0x00000411 | 유니코드: 0x00010411 |
| ko-KR | 한국어(한국) | 기본값: 0x00000412 | 한국어 Xwansung - 유니코드: 0x00010412 |
| de-DE | 독일어(독일) | 사전: 0x00000407 | 전화 Book Sort DIN: 0x00010407 |
| hu-HU | 헝가리어(헝가리) | 기본값: 0x0000040e | 기술 정렬: 0x0001040e |
| ka-GE | 조지아어(조지아) | 기존: 0x00000437 | 최신 정렬: 0x00010437 |
현재 문화권 및 UWP 앱
UWP(유니버설 Windows 플랫폼) 앱에서 CurrentCulture 및 CurrentUICulture 속성은 .NET Framework 및 .NET Core 앱과 마찬가지로 읽기/쓰기입니다. 그러나 UWP 앱은 단일 문화권만 인식합니다. CurrentCulture및 CurrentUICulture 속성은 Windows 첫 번째 값에 매핑됩니다. ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages 컬렉션입니다.
.NET Framework 및 .NET Core 앱에서 현재 문화권은 스레드별 설정이며 CurrentCulture 및 CurrentUICulture 속성은 현재 스레드의 문화권 및 UI 문화권만 반영합니다. UWP 앱에서 현재 문화권은 Windows 매핑합니다. 전역 설정인 ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages 컬렉션입니다. 또는 속성을 설정하면 CurrentCulture CurrentUICulture 전체 앱의 문화권이 변경됩니다. 문화권은 스레드 단위로 설정할 수 없습니다.
생성자
| CultureInfo(Int32) |
문화권 식별자별로 지정된 문화권을 기반으로 하는 CultureInfo 클래스의 새 인스턴스를 초기화합니다. |
| CultureInfo(Int32, Boolean) |
CultureInfo문화권 식별자가 지정한 문화권 및 Windows 사용자가 선택한 문화권 설정을 사용할지 여부를 지정하는 값에 따라 클래스의 새 인스턴스를 초기화합니다. |
| CultureInfo(String) |
이름에 지정된 문화권을 기반으로 CultureInfo 클래스의 새 인스턴스를 초기화합니다. |
| CultureInfo(String, Boolean) |
CultureInfo이름으로 지정된 문화권과 Windows 사용자가 선택한 문화권 설정을 사용할지 여부를 지정하는 값에 따라 클래스의 새 인스턴스를 초기화합니다. |
속성
| Calendar |
문화권에서 사용하는 기본 달력을 가져옵니다. |
| CompareInfo |
문화권에 대한 문자열을 비교하는 방법을 정의하는 CompareInfo를 가져옵니다. |
| CultureTypes |
현재 CultureInfo 개체와 관련된 문화권 형식을 가져옵니다. |
| CurrentCulture |
현재 스레드 CultureInfo 및 작업 기반 비동기 작업에서 사용하는 문화권에 해당하는 개체를 가져오거나 설정합니다. |
| CurrentUICulture |
리소스 관리자가 런타임에 문화권 관련 리소스를 찾기 위해 사용하는 현재 사용자 인터페이스를 나타내는 CultureInfo 개체를 가져오거나 설정합니다. |
| DateTimeFormat |
날짜와 시간 표시를 위한 문화권 형식을 정의하는 DateTimeFormatInfo 를 가져오거나 설정합니다. |
| DefaultThreadCurrentCulture |
현재 애플리케이션 도메인의 스레드에 대한 기본 문화권을 가져오거나 설정합니다. |
| DefaultThreadCurrentUICulture |
현재 애플리케이션 도메인의 스레드에 대한 기본 UI 문화권을 가져오거나 설정합니다. |
| DisplayName |
전체 지역화된 문화 이름을 가져옵니다. |
| EnglishName |
문화권 이름을 languagefullcountry/regionfull 형식으로 가져옵니다. |
| IetfLanguageTag |
더 이상 사용되지 않습니다. RFC 4646 표준 식별 언어를 가져옵니다. |
| InstalledUICulture |
운영 체제에 설치된 문화권을 나타내는 CultureInfo를 가져옵니다. |
| InvariantCulture |
문화권 독립(고정)적인 CultureInfo 개체를 가져옵니다. |
| IsNeutralCulture |
현재 CultureInfo가 중립 문화권을 표시하는지 여부를 나타내는 값을 가져옵니다. |
| IsReadOnly |
현재 CultureInfo가 읽기 전용인지 여부를 나타내는 값을 가져옵니다. |
| KeyboardLayoutId |
활성 입력 로캘 식별자를 가져옵니다. |
| LCID |
현재 CultureInfo에 대한 문화권 식별자를 가져옵니다. |
| Name |
languagecode2-country/regioncode2 형식의 문화권 이름을 가져옵니다. |
| NativeName |
문화권에서 표시하도록 설정된 문화권 이름(언어, 국가/지역 및 선택적 스크립트로 구성됨)을 가져옵니다. |
| NumberFormat |
숫자, 통화 및 백분율 표시를 위한 문화권 형식을 정의하는 NumberFormatInfo를 가져오거나 설정합니다. |
| OptionalCalendars |
문화권에서 사용할 수 있는 달력 목록을 가져옵니다. |
| Parent |
현재 CultureInfo의 부모 문화권을 나타내는 CultureInfo를 가져옵니다. |
| TextInfo |
문화권과 관련된 쓰기 시스템을 정의하는 TextInfo를 가져옵니다. |
| ThreeLetterISOLanguageName |
현재 CultureInfo 언어를 나타내는 세 문자로 된 ISO 639-2 코드를 가져옵니다. |
| ThreeLetterWindowsLanguageName |
Windows API에 정의된 해당 언어를 나타내는 세 문자로 된 코드를 가져옵니다. |
| TwoLetterISOLanguageName |
현재 CultureInfo 언어를 나타내는 두 문자로 된 ISO 639-1 코드를 가져옵니다. |
| UseUserOverride |
현재 CultureInfo 개체에서 사용자가 선택한 문화권 설정을 사용하는지 여부를 나타내는 값을 가져옵니다. |
메서드
| ClearCachedData() |
캐시된 문화권 관련 정보를 새로 고칩니다. |
| Clone() |
현재 CultureInfo의 복사본을 만듭니다. |
| CreateSpecificCulture(String) |
지정된 이름과 관련된 특정 문화권을 나타내는 CultureInfo을(를) 만듭니다. |
| Equals(Object) |
지정된 개체가 현재 CultureInfo와 같은 문화권인지 여부를 확인합니다. |
| GetConsoleFallbackUICulture() |
기본 그래픽 사용자 인터페이스 문화권이 적합하지 않은 경우 콘솔 애플리케이션에 적합한 대체 사용자 인터페이스 문화권을 가져옵니다. |
| GetCultureInfo(Int32) |
지정된 문화권 식별자를 사용하여 문화권의 캐시된 읽기 전용 인스턴스를 검색합니다. |
| GetCultureInfo(String) |
지정된 문화권 이름을 사용하여 문화권의 캐시된 읽기 전용 인스턴스를 검색합니다. |
| GetCultureInfo(String, Boolean) |
문화권의 캐시된 읽기 전용 인스턴스를 검색합니다. |
| GetCultureInfo(String, String) |
문화권의 캐시된 읽기 전용 인스턴스를 검색합니다. 매개 변수는 다른 문화권이 지정하는 TextInfo 및 CompareInfo 개체를 사용하여 초기화되는 문화권을 지정합니다. |
| GetCultureInfoByIetfLanguageTag(String) |
더 이상 사용되지 않습니다. 지정된 RFC 4646 언어 태그에 의해 언어적 특성이 식별되는 읽기 전용 CultureInfo 개체를 검색합니다. |
| GetCultures(CultureTypes) |
지정된 CultureTypes 매개 변수에 의해 필터링된 지원 문화권 목록을 가져옵니다. |
| GetFormat(Type) |
지정된 형식의 서식을 지정하는 방법을 정의하는 개체를 가져옵니다. |
| GetHashCode() |
해시 알고리즘과 해시 테이블 같은 데이터 구조에 적합한 현재 CultureInfo에 대한 해시 함수의 역할을 합니다. |
| GetType() |
현재 인스턴스의 Type을 가져옵니다. (다음에서 상속됨 Object) |
| MemberwiseClone() |
현재 Object의 단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| ReadOnly(CultureInfo) |
지정된 CultureInfo 개체의 읽기 전용 래퍼를 반환합니다. |
| ToString() |
languagecode2-country/regioncode2 형식으로 현재 CultureInfo의 이름을 포함하는 문자열을 반환합니다. |