C#字符串浮动?

前端之家收集整理的这篇文章主要介绍了C#字符串浮动?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在这里有一点代码
int i = 0;

        StreamReader re = File.OpenText("TextFile1.txt");
        string input = null;

        while ((input = re.ReadLine()) != null)
        {
            string[] sites = input.Split(' ');
            for (int j = 0; j < sites.Length; j++)
            {
                MyArray[i,j] = Convert.ToInt32(sites[j]);
            }
            i++;
        }


     for (int a = 0; a < 5; a++)
     {
            for (int j = 0; j < 5; j++)
            {
                Console.Write(MyArray[a,j] + " ");

            }
            Console.WriteLine();
     }

我的问题是这行代码

MyArray[i,j] = Convert.ToInt32(sites[j]);

它被转换为int,如何将其转换为浮点数?

解决方法

MyArray[i,j] = Convert.ToSingle(sites[j]);
原文链接:https://www.f2er.com/csharp/95458.html

猜你在找的C#相关文章