- Home /
Convert .js to C#
Hello I recently bought "Edy's Vehicle Physics" and have been trying to convert it to C# and I don't know how to convert this line, please help.
static var MCforward = [ 0.561, 1.114, 1.659, 2.195, 2.724, 3.246, 3.759, 4.266, 4.765, 5.257, 5.741, 6.219, 6.690, 7.154, 7.611, 8.062, 8.506, 8.944, 9.376, 9.801, 10.223, 10.636, 11.044, 11.443, 11.839, 12.229, 12.614, 12.990, 13.363, 13.731, 14.095, 14.452, 14.805, 15.153, 15.496, 15.834, 16.167, 16.495, 16.819, 17.138, 17.453, 17.772, 18.078, 18.380, 18.667, 18.970, 19.260, 19.545, 19.826, 20.103 ];
static var MCsideways = [ 0.555, 1.095, 1.622, 2.135, 2.636, 3.124, 3.600, 4.060, 4.513, 4.951, 5.382, 5.793, 6.199, 6.602, 7.002, 7.348, 7.723, 8.096, 8.419, 8.782, 9.101, 9.403, 9.779, 10.026, 10.322, 10.695, 10.921, 11.157, 11.465, 11.807, 12.005, 12.202, 12.440, 12.741, 13.060, 13.234, 13.394, 13.570, 13.780, 14.033, 14.333, 14.567, 14.707, 14.835, 14.969, 15.119, 15.291, 15.489, 15.714, 15.966 ];
Thanks Tz
Answer by n8 · Dec 06, 2012 at 05:16 PM
these are just float arrays. They should just be something like this:
static float[] MCforward = new float[] {0.561f, 1.114f, 1.659f};
static float[] MCsideways = new float[]{0.555f, 1.095f, 1.622f};
Answer by Landern · Dec 06, 2012 at 05:20 PM
Here you go, as List of float.
static List<float> MCforward = new List<float>() { 0.561f, 1.114f, 1.659f, 2.195f, 2.724f, 3.246f, 3.759f, 4.266f, 4.765f, 5.257, 5.741f, 6.219f, 6.690f, 7.154f, 7.611f, 8.062f, 8.506f, 8.944f, 9.376f, 9.801f, 10.223f, 10.636f, 11.044f, 11.443f, 11.839f, 12.229f, 12.614f, 12.990f, 13.363f, 13.731f, 14.095f, 14.452f, 14.805f, 15.153f, 15.496f, 15.834f, 16.167f, 16.495f, 16.819f, 17.138f, 17.453f, 17.772f, 18.078f, 18.380f, 18.667f, 18.970f, 19.260f, 19.545f, 19.826f, 20.103f };
static List<float> MCsideways = new List<float>() { 0.555f, 1.095f, 1.622f, 2.135f, 2.636f, 3.124f, 3.600f, 4.060f, 4.513f, 4.951f, 5.382f, 5.793f, 6.199f, 6.602f, 7.002f, 7.348f, 7.723f, 8.096f, 8.419f, 8.782f, 9.101f, 9.403f, 9.779f, 10.026f, 10.322f, 10.695f, 10.921f, 11.157f, 11.465f, 11.807f, 12.005f, 12.202f, 12.440f, 12.741f, 13.060f, 13.234f, 13.394f, 13.570f, 13.780f, 14.033f, 14.333f, 14.567f, 14.707f, 14.835f, 14.969f, 15.119f, 15.291f, 15.489f, 15.714f, 15.966f };
Lists are great to use in place of standard arrays as they give more control over the contents, just keep in $$anonymous$$d that you need to import the proper libraries to get these to work. Add this to the top of your file:
using System.Collections; using System.Collections.Generic;
You only need to declare :
c# using System.Collections.Generic;
js import System.Collections.Generic;
for a List of T(T = the Type that will make up the elements in your collection.
Your answer
Follow this Question
Related Questions
Need help converting js to C# 1 Answer
Cloud recognition in Vuforia 0 Answers
A convert between stream and object in unity3d? 0 Answers