Created
October 26, 2023 22:28
-
-
Save bitbonk/20352130cbc074417c08513d307b1d51 to your computer and use it in GitHub Desktop.
asynclocal culture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See https://aka.ms/new-console-template for more information | |
using System.Globalization; | |
using System.Runtime.CompilerServices; | |
ShowCulture("start"); | |
await SetFrenchAsync(); | |
ShowCulture("end"); | |
async Task SetFrenchAsync() | |
{ | |
ShowCulture(" start", "fench"); | |
CultureInfo.CurrentCulture = new CultureInfo("fr-fr"); | |
ShowCulture(" changed", "fench"); | |
await Task.Delay(100); | |
await SetGermanAsync(); | |
ShowCulture(" end", "fench"); | |
} | |
async Task SetGermanAsync() | |
{ | |
ShowCulture(" start", "german"); | |
CultureInfo.CurrentCulture = new CultureInfo("de-de"); | |
ShowCulture(" changed","german"); | |
await Task.Delay(100); | |
await SetRussianAsync(); | |
ShowCulture(" end","german"); | |
} | |
async Task SetRussianAsync() | |
{ | |
ShowCulture(" start", "russian"); | |
CultureInfo.CurrentCulture = new CultureInfo("ru-ru"); | |
ShowCulture(" changed","russian"); | |
await Task.Delay(100); | |
ShowCulture(" end","russian"); | |
} | |
void ShowCulture(string text, [CallerMemberName] string methodName = "") | |
{ | |
Console.WriteLine(text + methodName + " : " + CultureInfo.CurrentCulture); | |
} | |
// start<Main>$ : en-DE | |
// startfench : en-DE | |
// changedfench : fr-FR | |
// startgerman : fr-FR | |
// changedgerman : de-DE | |
// startrussian : de-DE | |
// changedrussian : ru-RU | |
// endrussian : ru-RU | |
// endgerman : de-DE | |
// endfench : fr-FR | |
// end<Main>$ : en-DE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment