Came up with this snipet and it writes out a hundred "1" in the console, which means the tester (your "Main") does see the right values.
To be completely honnest, I dont have any clue what your problem is since we dont see your whole code. You'll have to figure out yourself unless you post your whole solution. The code you posted does work the way you said it should.
Long story short: I added the pieces needed in order to run, and not only does it run, it doesnt show any bug. You might want to compare your code with the one below.
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
tester.writeOut();
}
}
class Something
{
private int firstDimensionLenght = 10;
private int secondDimensionLenght = 10;
private int[,] xArray;
public Something()
{
xArray = new int[firstDimensionLenght, secondDimensionLenght];
for (int row = 0; row < xArray.GetLength(0); row++)
for (int col = 0; col < xArray.GetLength(1); col++)
xArray[row, col] = 1;
}
//Add some intellisence information stating you clone the initial array
public int[,] XArrayCopy
{
get { return (int[,])xArray.Clone(); }
}
}
class tester
{
static Something some;
//We dont want to initialize "some" every time, do we? This constructor
//is called implicitly the first time you call a method or property in tester
static tester(){
some = new Something()
}
//This code is painfuly long to execute compared to what it does
public static void writeOut()
{
for (int row = 0; row < some.XArrayCopy.GetLength(0); row++)
for (int col = 0; col < some.XArrayCopy.GetLength(1); col++)
Console.Write(some.XArrayCopy[row, col].ToString());
}
//This code should be much smoother
public static void wayMoreEfficientWriteOut()
{
int[,] localArray = some.XArrayCopy();
for (int row = 0; row < localArray.GetLength(0); row++)
for (int col = 0; col < localArray.GetLength(1); col++)
Console.Write(localArray[row, col].ToString());
}
}
}
var1, var2in this linexArray = new int[var1, var2];have you used the debugger to step through the code ...?some.in your Console.Write statement, but I doubt that's your problem because your code shouldn't compile with that error. Perhaps you should flesh this example out into a complete program so we can reproduce your error exactly. Note also that you are cloning the array 2 + var1 * var2 times, because it is cloned each time you call the XArray property in thewriteOutmethod.XArray. Consider storing the array into a local variable.