locked
object[,] - meaning RRS feed

  • Question

  • I was referencing to a code snip on this page http://www.dotnetperls.com/excel, but could not exactly figure out what does "object[,]" means ?

    Well, that code is regarding using Excel Inerop libraries to manipulate excel files with C#. I think the program intends to store all the values of cell address and its respective value in the object array may be ?

    But I am still not getting the mechanism of "object[,]" ... turns out to be something really line-of-code saving efficient thing, friends, please help me understand this.

    Thanks much,

    -Aarsh


    Sunday, December 2, 2012 6:02 PM

Answers

  • Yes, you are quite correct; I mis-spoke. The post should read:
    ---------------------------------------------------------------------

    Yes,
       excelRange.get_Value(XlRangeValueDataType.xlRangeValueDefault)
    is being cast to a 2D array with this statement. The C# common superclass equivalent to the VBA type returned by Excel is object.


    "Premature optimization is the root of all evil." - Knuth

    If I provoked thought, please click the green arrow

    If I provoked Aha! please click Propose as Answer


    Monday, December 3, 2012 3:13 PM

All replies

  • It means a 2-D array of object, which might be used as follows:

    object[,] o = new object[2,3];
    


    "Premature optimization is the root of all evil." - Knuth

    If I provoked thought, please click the green arrow

    If I provoked Aha! please click Propose as Answer

    • Proposed as answer by Deepak Kalra Monday, December 3, 2012 7:28 AM
    Sunday, December 2, 2012 6:14 PM
  • Thanks Pieter.

    So here is the thing,

    object[,] valueArray = (object[,])excelRange.get_Value(
    	    XlRangeValueDataType.xlRangeValueDefault);
    

    valueArray would be declared as a 2-d array - ok got it, but the expression on the right side is still confusing me, by any chance does it means that whatever gets evaluated, is casted, and can be casted in to 2-D array ?

    Sunday, December 2, 2012 6:32 PM
  • Yes,
       excelRange.get_Value(XlRangeValueDataType.xlRangeValueDefault)
    is being cast to a 2D array with this statement. The C# equivalent of the VBA Variant is object.

    "Premature optimization is the root of all evil." - Knuth

    If I provoked thought, please click the green arrow

    If I provoked Aha! please click Propose as Answer


    Sunday, December 2, 2012 7:09 PM
  • Yes,
       excelRange.get_Value(XlRangeValueDataType.xlRangeValueDefault)
    is being cast to a 2D array with this statement. The C# equivalent of the VBA Variant is object.

    The VB equivalent for "Object" is "Object".

    The VB equivalent for "Variant" is "dynamic".

    Monday, December 3, 2012 3:05 PM
  • Yes, you are quite correct; I mis-spoke. The post should read:
    ---------------------------------------------------------------------

    Yes,
       excelRange.get_Value(XlRangeValueDataType.xlRangeValueDefault)
    is being cast to a 2D array with this statement. The C# common superclass equivalent to the VBA type returned by Excel is object.


    "Premature optimization is the root of all evil." - Knuth

    If I provoked thought, please click the green arrow

    If I provoked Aha! please click Propose as Answer


    Monday, December 3, 2012 3:13 PM