Classes advice needed

This is a discussion on Classes advice needed within the C# Programming forums, part of the General Programming Boards category; I've successfully created a class with um, well, here:
Code:
using System;
namespace SP2ClassLibrary
{
public class TechClass
{
/// ...

And I obviously start this with a normal 'TechClass tech = new TechClass();' (with the appropriate using).

I will obviously change it to a get/set system if you seriously recommend doing so.

First off, what is the best way to convert the property from tech.AT[x] to tech[x].AT? Make it TechClass[] tech = new TechClass[12];? I do suspect that would be the way. BTW, x is the player number, and the letters represent the specific technology level of the player, AT is agricultural tech, so tech.AT[0] is the Agricultural Tech Level of player zero.

After switching this around, I would like to understand how to add um, submethods (sorry, names ALWAYS escape me!). For example, my program does a lot of calculations using these variables, especially text output to a form. One such case is properly formatting this on a form. It would be a lot more readable to have something such as tech[0].AT.Name (as a string type), or tech[0].AT.SpacedString that outputs the variable number (ie. 1) as a string with a set of preceding spaces. My aim is to achieve a very high level of readability in my code, and also to learn more about classes. Anyone up to this?

The easiest way is to dive down a bit deeper and instead of representing all the players levels in one object, represent each player with those attributes as an object. Then keep a collection of those objects.

However, I want a property/variable called AdjSystem, to be an array of size 7. So I'd write it as system[x].AdjSystem[y] . This is the only one in this style, as I am wanting the ability to iterate through the number of adjacent systems this system has. I currently have this in the constructor:

Are you trying to initialize the adj array? Are you doing the same for loop you did with the other array in which you new each object in the adj array? (unless you are assigning them to existing objects.)

However, I want a property/variable called AdjSystem, to be an array of size 7. So I'd write it as system[x].AdjSystem[y] . This is the only one in this style, as I am wanting the ability to iterate through the number of adjacent systems this system has. I currently have this in the constructor:

This only initialises as null, not the desired array. How can I do this?

Answering in reverse. First, notice that in your SystemClass constructor, you are declaring a local _AdjSystem which you are initializing. That local goes out of scope at the end of the constructor. Meanwhile, your class-scope _AdjSystem is never initialized. Try this:

Code:

public SystemClass()
{
_AdjSystem = new int[7];
//... and other bits in here
}

If you want the system[x].AdjSystem[y] syntax, you might consider an indexer property instead of exposing the whole array to everything outside of the class.

If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein