0

I am having difficulty reading values from the following object type array returned from Oracle stored procedure

var arrUtil = cmd.Parameters["UTILBYDAY"].Value;

The arrUtil array is of the below type and has these values. Any idea how to cast it to double type in c#?

{Oracle.ManagedDataAccess.Types.OracleDecimal[10]}
    [0]: {28.16901408450704225352112676056338028169}
    [1]: {57.24381625441696113074204946996466431095}
    [2]: {29.34782608695652173913043478260869565217}
    [3]: {22.02166064981949458483754512635379061372}
    [4]: {70.56737588652482269503546099290780141844}
    [5]: {79.78723404255319148936170212765957446809}
    [6]: {62.41134751773049645390070921985815602837}
    [7]: {23.40425531914893617021276595744680851064}
    [8]: {5.31914893617021276595744680851063829787}
    [9]: {63.507109004739336492890995260663507109}

I have tried to cast it to double using

double[] arraUtil = (double[]) cmd.Parameters["UTILBYDAY"].Value;

but it ended up in error that said unable to cast Oracle.ManagedDataAccess.Types.OracleDecimal[] to double[].

I have also tried googled around but couldn't find anything helpful. Any help is appreciated. Thank you.

2
  • this is not convertible to double at all, so please clarify Commented Dec 14, 2022 at 10:59
  • What can it be converted to? Any type is fine as long as I could read the values out... Commented Dec 14, 2022 at 22:36

1 Answer 1

1

Oracle.ManagedDataAccess.Types.OracleDecimal type defines an explicit cast operator to convert its value to double type.

You can convert them like this:

using System.Linq;
using Oracle.ManagedDataAccess.Types;

OracleDecimal[] arrUtil = cmd.Parameters["UTILBYDAY"].Value;

// Convert to double
double[] utils = arrUtil.Select(util => (double)util).ToArray();

// Convert to decimal
decimal[] utils = arrUtil.Select(util => (decimal)util).ToArray();

// Please note: This does NOT work!
double[] utils = arrUtil.Cast<double>().ToArray();

You can cast OracleDecimal to byte, short, int, long, float, double and decimal.

Here you can find all the explicit cast operators.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.