Thanks! i have solved this thing it is realy preety simple :) public class Matrika { public int mat_x; public int mat_y; public Array matrika; public Matrika(int x, int y) { //i needed to save separated x and y and create 2D array mat_x = x; mat_y = y; matrika = Array.CreateInstance(typeof(int), x, y); {
But, why did you say that public atributes are no ok?
av7254
Posts
-
Getting a value from a constructor -
Getting a value from a constructorSo, how do i make it member of class, that will conatain x=5 and y=5 in this case. "polzisce" has to be object wich contains a 2d array wich is specified with this Matrika polzisce = new Matrika(5,5); Tnx for your answers :)
-
Getting a value from a constructoryour way is simplier but, i want to do it like this. all i want is to get the x and y value from constructor. Use cases: Matrika polzisce = new Matrika(10,20); Matrika polzisce = new Matrika(5,2); maybe: Matrika polzisce = new Matrika(1000,1000); in this case: Matrika polzisce = new Matrika(5,5); Constructor runes first when object is created and contains varibles x=5 and y=5(actualy limits of array). I need those two to create two-dimensional array. I don't know how to access those varibles in the constructor, that i can create 2d array and that object "polzisce" will contain 2d array 5x5 Tnx for all other posts! I appreciate!
-
Getting a value from a constructorHello, I created an object "polzisce" from a class called Matrika(this is class that creates two dimensional array) and it's constructor takes two parameters. Those two parameters are actualy X an Y axis and they are not fixed size. public class Matrika { //constructor public Matrika(int x, int y) { int[,] matrika = new int[x, y]; } } static void Main(string[] args) { Matrika polzisce = new Matrika(5, 5); } The question is: Is object "polzisce" actualy two dimensional array after it is created? How can i get that two-dimensional array "matrika" from constructor? Thanks! Alen.