小编div*_*481的帖子

C# 解析来自不同语言环境的 int

我知道,还有其他类似的问题,例如将数字转换为特定于文化的

但是我遇到了困难,即使答案对我也不起作用。仍然得到 System.FormatException: '输入字符串的格式不正确。'

我的当前/系统语言环境是 de,我正在解析一个 en int。到目前为止,无论我尝试过什么(包括之前问题的答案,都不起作用。

那么,我错过了什么?


            string numberStr = "1,111"; // one thousand one hundred eleven

            //int result = int.Parse(numberStr);
            //int result = int.Parse(numberStr, CultureInfo.GetCultureInfo("en-US").NumberFormat);
            //int result = int.Parse(numberStr, CultureInfo.InvariantCulture);
            //int result = int.Parse(numberStr, CultureInfo.InvariantCulture.NumberFormat);
            //int result = int.Parse(numberStr, CultureInfo.GetCultureInfo("en-UK").NumberFormat);
            int result = int.Parse(numberStr, CultureInfo.GetCultureInfo("en"));

            Console.WriteLine(result);
Run Code Online (Sandbox Code Playgroud)

c# .net-core

2
推荐指数
2
解决办法
192
查看次数

标签 统计

.net-core ×1

c# ×1