I'm (very) new to C#; I'm sure the solution here is simple but I can't figure it out.
Suppose I have a simple array of temperatures for Friday. I receive an abbreviation for the day and an hour (integer) from somewhere and I want to use it to print an element from the array:
using System;
public class Program
{
public static void Main()
{
double[] Friday = {54.5, 61.0, 63.5, 58.0};
string Today = "Fri";
int Hour = 1;
double parsed = Convert.ToDouble(Today + "day[" + int + "]");
Console.WriteLine(parsed);
}
}
Given these conditions, how do I output 61.0? Then end result should be equivalent to Console.WriteLine(Friday[1]);
Convert.ToDouble()in the same way as JavascriptsEval(). There is no equivalent forEvalin the c# language, nothing will simply take a string and interpret it as code. If you tell us some more information about what your ultimate goal is, we can find an alternative approach to the problem.