[英]need help translating a code snippet from java to C# equivalent
Here's the code snippet I'd like to translate from Java to C#. 这是我想从Java转换为C#的代码片段。 I'm not sure what's causing the error but I've never used ArrayLists and vectors before.
我不确定是什么导致了错误,但我之前从未使用过ArrayLists和vectors。 Thanks in advance!!
提前致谢!!
//Java class definitions, constructors, fields, methods etc here.
//sphbasis is a Vector object.
public SphericalHarmonicDecomposition[] getSphericalHarmonicBasis() {
return (SphericalHarmonicDecomposition[])(sphbasislist.toArray(
new SphericalHarmonicDecomposition[sphbasislist.size()]));
}
I've tried doing the following in C#: 我尝试在C#中执行以下操作:
//C# class definitions, constructors, fields, methods etc here.
//sphbasis is a ArrayList object.
public SphericalHarmonicDecomposition[] getSphericalHarmonicBasis() {
return (SphericalHarmonicDecomposition[])(sphbasislist.ToArray(
new SphericalHarmonicDecomposition[sphbasislist.Count]));
}
I get the following errors. 我收到以下错误。 I'm using Mono and Xamarin studio on a mac.
我在Mac上使用Mono和Xamarin Studio。
Error CS1502: The best overloaded method match for
`System.Collections.ArrayList.ToArray(System.Type)'
has some invalid arguments (CS1502) (projectx)
and 和
Error CS1503: Argument `#1' cannot convert
`matdcal.engine.model.SphericalHarmonicDecomposition[]' expression
to type `System.Type' (CS1503) (projectx)
Please try the following. 请尝试以下方法。 In Java you need to pass an array to the
toArray
method, but that's not correct in C# (.NET). 在Java中,您需要将数组传递给
toArray
方法,但这在C#(.NET)中是不正确的。
//C# class definitions, constructors, fields, methods etc here.
//sphbasis is a ArrayList object.
public SphericalHarmonicDecomposition[] getSphericalHarmonicBasis() {
return (SphericalHarmonicDecomposition[])(sphbasislist.ToArray());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.