How to access the first value from an object in C # 3.0
How can I access the first value from
object t = (object) wsf.LinEst(y.ToArray(), x.ToArray(), false, true);
Output signal
object[1..5, 1..2]}
[1, 1]: 0.17134831460674155
[1, 2]: 0.0
[2, 1]: 0.019612696690686725
[2, 2]: -2146826246
[3, 1]: 0.95020429009193053
[3, 2]: 0.82746057986828336
[4, 1]: 76.328205128205056
[4, 2]: 4.0
[5, 1]: 52.261235955056179
[5, 2]: 2.7387640449438226
I only need to get the value [1,1] ie 0.17134831460674155
How to get it.
LinEst only returns an object.
I am using C # 3.0
thanks
thanks
a source to share
Well, it looks like you can enumerate which returns doubles - although it really can't implement IEnumerable<double>
. Try this (with a directive using System.Linq;
at the top of your code):
IEnumerable t = (IEnumerable) wsf.LinEst(y.ToArray(), x.ToArray(), false, true);
double first = t.Cast<double>().First();
However, this won't work if it actually returns something like int[][]
. Could you tell us more about the fact that he is indeed returning? Yes, it declared that it returns object
, but it clearly returns something more. If you know it will always return object[,]
with 1-based indices, you can apply the following to them:
object[,] t = (object[,]) wsf.LinEst(y.ToArray(), x.ToArray(), false, true);
double first = (double) t[1, 1];
If you don't know the lower bounds of the array, you can query them programmatically, of course ... but the LINQ way will probably be easier.
a source to share
You can force the corresponding type of broadcast.
Instead of this:
object t = (object) wsf.linEst(etc.)
try
int[,] t = (int[,]) wsf.linEst(etc.)
This is because the linEst function doesn't just return an instance of the Object class.
The result you included in your question seems to imply that the debugger can determine the runtime type of your object t, so try using that information to cast it correctly.
Either that or wsf.linEst doesn't just return an object and you add text (object)
that makes the return value be put into a variableobject t
a source to share