更新时间:2023-02-10 14:18:13
有许多可能的解决方案.这是一个:
Hi,
there are many possible solutions for this. Here is one:
public static int[] ConvertDoubleArrayToIntArray(double[] adDoubleArray)
{
return adDoubleArray.Select(d => (int)d).ToArray();
}
并像这样使用:
and use like this:
double[] adDoubleArray = { 1.1d, 2.2d, 3.3d, 4.4d, 5.5d };
int[] aiIntArray = ConvertDoubleArrayToIntArray(adDoubleArray);
这可能会有所帮助,
Convert.ToInt32 [
It might be helpful,
Convert.ToInt32 [^]
an example,
static void Main(string[] args)
{
double[] myDoubleArray = { 114.4, 225.0, 11.7 };
IList<Int32> myInt32List = new List<Int32>();
Array.ForEach(myDoubleArray, item =>
{
myInt32List.Add(Convert.ToInt32(item));
});
Int32[] myInt32Array = myInt32List.ToArray();
}
:)
:)
我认为您别无选择,只能编写一些LINQ或foreach来遍历列表并一次转换一次.
I think you have no choice but to write some LINQ or a foreach to iterate over your list and convert one at a time.