简体   繁体   English

JavaScript到C#的转换-未知数据类型

[英]JavaScript to C# conversion - unknown data type

Hi I am converting JavaScript to C# code, however I cannot figure out how would I write the following into C#? 嗨,我正在将JavaScript转换为C#代码,但是我不知道如何将以下内容写入C#? Any help? 有什么帮助吗?

var MyValues = { 
"Values1": [ 
    0.0, 2.33, -3,
    0.0, 1.0,      0.0,
    0.0, 0.0,      1.0
],
"Values2": [ 
    1.0,      2.0, 0.0,
    1.567207, 0.0, 2.224827,
    0.2,      0.0, 1.0
],
"Values3": [
    0.0,       0.0,      0.0,
    0.0,       1.0,      0.0,
    -3.222, 1.2209, 0.0
]

}; };

This compiles 这样编译

var MyValues = new
{
    Values1 = new[]{
        0.0, 2.33, -3,
        0.0, 1.0,      0.0,
        0.0, 0.0,      1.0
    },
    Values2 = new[]{ 
        1.0,      2.0, 0.0,
        1.567207, 0.0, 2.224827,
        0.2,      0.0, 1.0
    },
    Values3 = new[]{
        0.0,       0.0,      0.0,
        0.0,       1.0,      0.0,
        -3.222, 1.2209, 0.0
    }
};

You can do this. 你可以这样做。 This is an explicit way of doing it. 这是一种明确的方式。

    static void Main(string[] args)
    {
        Dictionary<String, double[]> dict = new Dictionary<string, double[]>();
        dict.Add("Values1", new double[] { 0.0, 2.33, -3, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 });
        dict.Add("Values2", new double[] { 1.0, 2.0, 0.0, 1.567207, 0.0, 2.224827, 0.2, 0.0, 1.0 });
        dict.Add("Values3", new double[] { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -3.222, 1.2209, 0.0 });
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM