0

I am using OxyPlot, a graphing library for C#. What confuses me so far is the type for some of the constructors. A code snippet is below:

public static PlotModel Notinterpolatedvalues() {
            var plotModel1 = new PlotModel();
            plotModel1.Subtitle = "Input text here";

            var linearColorAxis1 = new LinearColorAxis();
            linearColorAxis1.HighColor = OxyColors.Gray;
            linearColorAxis1.LowColor = OxyColors.Black;
            linearColorAxis1.Position = AxisPosition.Right;
            plotModel1.Axes.Add(linearColorAxis1);

            var linearAxis1 = new LinearAxis();
            linearAxis1.Position = AxisPosition.Bottom;
            plotModel1.Axes.Add(linearAxis1);

            var linearAxis2 = new LinearAxis();
            plotModel1.Axes.Add(linearAxis2);

            var heatMapSeries1 = new HeatMapSeries();
            heatMapSeries1.X0 = 0.5;
            heatMapSeries1.X1 = 1.5;
            heatMapSeries1.Y0 = 0.5;
            heatMapSeries1.Y1 = 2.5;
            heatMapSeries1.Interpolate = false;

            heatMapSeries1.Data = new Double[2, 3];
            heatMapSeries1.Data[0, 0] = 0;
            heatMapSeries1.Data[0, 1] = 0.2;
            heatMapSeries1.Data[0, 2] = 0.4;
            heatMapSeries1.Data[1, 0] = 0.1;
            heatMapSeries1.Data[1, 1] = 0.3;
            heatMapSeries1.Data[1, 2] = 0.2;

            plotModel1.Series.Add(heatMapSeries1);
            return plotModel1;
        }

This generates this image:

enter image description here

(It's a heat map)

My question is - what is var? For example, when you create a new multidimensional array, you do this:

double[,] doubleArray = new double[columns, rows];

Understandingly, the type for this is a double[,]. Why I need to know this is that I would like to store the heatmap as an instance variable, more specifically, heatMapSeries1.Data as a multi-dimensional array. However, in VS, I am unable to declare var as the type for an instance variable. The only selection I get is this:

enter image description here

Any OxyPlot pros in here could lend me a hand? Thank you.

theGreenCabbage
  • 5,197
  • 19
  • 79
  • 169
  • This doesn't really have anything to do with Oxyplot - it's all about `var`. I suggest you read http://msdn.microsoft.com/en-us/library/bb383973.aspx and http://msdn.microsoft.com/en-us/library/bb384061.aspx – Jon Skeet Dec 06 '13 at 16:52
  • So it's implicitly declared? Well, it does have to do with OxyPlot if you ask me. I'd like to declare it explicitly, and in order to do that, I need to know the `type`. – theGreenCabbage Dec 06 '13 at 16:53
  • No, it's implicitly *typed*, based on the RHS of the assignment. It doesn't have anything to do with OxyPlot in that anyone who knows C# but doesn't know OxyPlot can still answer the question - whereas an OxyPlot expert who doesn't know about `var` will be confused. Look at the line that's using `var` to declare the `heatMapSeries1` variable and it's pretty obvious what the inferred type will be - once you understand the language. Hence the references to MSDN. Read those, and you'll be able to delete the question, I suspect :) – Jon Skeet Dec 06 '13 at 16:56
  • I see. Well, apologies, I'm fairly new to .NET. I'll go read it now. If I still don't know, could you tell me? – theGreenCabbage Dec 06 '13 at 16:57
  • Sure - but it'll be better if you learn it for yourself, of course. Have fun :) – Jon Skeet Dec 06 '13 at 16:58
  • Yep! Understandable. Hence why I didn't start my comment with "pls sir just gib me the ansrwr pls!!!" – theGreenCabbage Dec 06 '13 at 17:00
  • @JonSkeet This answer made a lot of sense to me: http://stackoverflow.com/a/3422732/1913389 Essentially, it's a convenience factor in the use of `var` in this instance like "when the type is elsewhere on the same line". – theGreenCabbage Dec 06 '13 at 17:42

0 Answers0