Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help On Constructors in nested 'Has a ' classes

Status
Not open for further replies.

bn2335813

Programmer
Oct 8, 2001
10
IL
Hi !
---

What is wrong with the code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Test1
{
public partial class Form1 : Form
{
public A aa;

public Form1()
{
aa = new A(10);
InitializeComponent(); // <--- BreakPoint
}
}

public class A
{

public B b;
public A(int n)
{
b = new B(n);
}

}

public class B
{
public C[] c;
public int x;

public B(int num)
{
x = num;
c = new C[num];
}

}

public class C
{
public int[] n=new int[200];
private int f;

public int F
{
set
{
f = value;
}
get
{
return f;
}
}

}
}

when I try to debug and see 'c' (no-CAP) I only see 10 cells with nulls instead of cells with 200 int with let's say '0' value !!!

Thanks !!
 
Here ...
you need to instantiate every instance of C to see it contain cells with 200 int
so your class B will look like this
public class B
{
public C[] c;
public int x;

public B(int num)
{
x = num;
c = new C[num];
for(int i=0; i<num;i++)
{
c= new C();
}
}

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top