Question is: Should I Declare a Class that is an Array not declared as such but is.
Or should I declare the Class with only the members that it contains knowing I must use some of them 6 Times at the same time?
All in the same string.
like in Example 1
class Horse
int[][][] Horse [2][]
then go on to instantiate it either here or in the Main method
Or Example 2
class Horse
class firstTrack : Horse
class second Track : Horse
class thirdTrack : Horse
then each of these subclasses is an Array as well
creating an Array of Arrays I must convert this to strings and perform manipulations and write to files and Database.
Or should I use The
List way of doing it?
before I proceed I must know if there are pitfalls
or easier ways possibly
Any Help would be appreciated Thank You in Advance

Recommended Answers

All 11 Replies

If I understand you well, I should have a Horse class, and put it in a List of Horses. Every Horse should have(among others) an int property Track(or something) giving you the track number.

generally it helps to try and model the rela world example first. So, sit down and work out what attributes each part of the model needs to have.
I'm guessing you are trying to write a program to deal with a race course of some sort..i'd start somewhere like:

Race Course
Name,
City,
Country,
Tracks*

Track
Number,
Name,
Horses*

Horse
Name,
Number?,
Rider*

Jockey
Name

NB: items marked with an asterix (*) attributes the item may have more than one of... a horse coudl neter more than one race, or be ridden by mroe than one jockey. If you are storing more than one of something, in code you use a collection. SO you would end up with classes like:

Class RaceCourse
{
    public string Name {get; set;}
    public string City {get; set;} 
    public string Country {get; set;}
    public List<Track> Tracks {get; set;}
}

Class Track
{
    public int Number {get; set;}
    public string Name {get; set;} 
    public List<Horse> Horses {get; set;}
}

Class Horse
{
    public int Number {get; set;}
    public string Name {get; set;} 
    public List<Jockey> Jockeys{get; set;}
}

Class Jockey
{
    public string Name {get; set;} 

}

I know very little about horseraces so apologies if the attributes are off (do horses get assigned numbers?).

Actually it is a file operation similar to a database operation The attributes would be like its color and such those are unimportanat as I know all of them
It is the actual syntax that eludes Me well not completely but the approach.
That is the question.
For instance if I use the get and set alone as stated above in the class declaration will I be in trouble later when trying to use the StreamWriter for file operations?
As to make the application viable for backwards compatibility and interaction with existing applications doing similar things.
In other words so the customer does not have to start all over with the files they have now
they can simply read them in and save or open them and save
and exchange with others who may not have this application easily.
So just using <List> will work for this?
I can use this across all Formats?
I guess that really is My question.
And can I use <List> in the Class Declaratioon?
As you have here?
Did not know that would work.
And the firstTrack is actually another Array so It is an Array of Arrays.
Hope I explained that better.
class Horse
class firstTrack : Horse
int[] firstTrack [72]
class second Track : Horse
int[] second Track [72]
class thirdTrack : Horse
int[] thirdTrack [72]
this is what I mean but this does not compile.
and the attributes in the track class are bytes
but when I try to declare same I get the conversion error saying I cannot convert there
so To declare in the class ?
So close ,,,,,, I already have all the other stuff worked out
at least as far as the actual computations anyway
But i am stumped I am missing something from some tutorial i am convinced of it.
So should I use the string instead?
When I do that I cannot use string inside of a string
Or I am not declaring it correctly.
One or the other
Each Horse Has 72 attributes x 3 Tracks that are saved in a text file
3 of each of those is a check sum an multiplyers
So you see I must do a calculation on each of them when editing or saving
I had figured on not saving the CRC calculation in the database
just get it to create a new one.
in this manner a user could exchange data across the internet or in whatever medium they want for this type of file
Thank you for the reply with great enthusiasm!

Sorry, you have totally lost me now : /
What are the files you are working with and what do you need to do with them?

You seem to have missed what i was trying to say, You are declaring firstTrack, secondTrack and thridTrack as seperate classes, but they are all going to hold an array of 72 bytes. So what you have is a track object that holds 72 bytes. So you should have something like:

class Track
{
    public int[72] Horse
}

Then you can have a List<Track> that holds 3 distinct instances of the Track class.
In the context of your program; what is a horse? To me a horse is a four legged animal...is this the horse you are refering to?
Also, why are you trying to make the Track Class inherit from the Horse Class (firstTrack : Horse)?

Actually it is a file operation similar to a database operation

Could you explain what it is?

It is a File ,. Sorry to be so vague . I didn't Realize I was doing that.
The file has three strings consisting of 73 Members each a Byte.
I must or wish to save them to a Database and keep the file operation I use now as well
Plus Edit them
They use a CRC checksum function as well
Must be used by the Strean Writer Reader Class along with the Binary converter class
I tried to declare the Class in the Manner above and it would not compile but I was also trying to instantiate it there as well perhaps that is what I did wrong.
Although I used

class Track{ public int[72] Horse}class Track
{
public int[72] Horse
// then I declared three here perhaps this was My mistake?
//also I had declared it as a Jagged Array
}
Or do you mean not to bother with the Horse class at all
as I really dont need that?
Just work with the 3 strings.?
Confusion Reigns supreme ,,,,,,,,
I was going to try that but got discouraged.

Why are you still talking about a Horse class? This is very confusing. I am not a native English speaker, does this counts for you also?
Would you please elaborate on what you mean by a Horse?

Why are you still talking about a Horse class? This is very confusing. I am not a native English speaker, does this counts for you also?
Would you please elaborate on what you mean by a Horse?

In this Game the Horse Represents the file itself . That is why I call it a Horse. Sorry I should have explained further.
Anyway the file is the Horse in the Game .
It represents the attributes of the Horse.
The only methods I will use are file methods.
Stream IO writer and Reader and functions for calculation

Could you explain what it is?

By the way this is a Very Nice looking site

try reading through this, it might help you to understand the basics of classes, also i wrote a tutorial a while back that might help too.

I read that before . I have only 3 Methods to the entire program.
The program works with 3 strings of hex code each 72 bytes or characters if you will
that I am not sure I understand if that is the same or not.byte and characters i mean .
0 to 255 each
The entire program works on the hex strings of each line or Track .
Editing and saving aqnd CRC checksum calculation
each File has 3 lines of hex or tracks
the file when in notepad or wordpad has the other file characteristics from another program.
read the 3 line in set them to text boxes and edit them and calculate the new checksum
Then send them directly to the Magnetic Encoder credit card Writer
or read from same
and try to store the strings in a database so they do not degrade so easily
As they are very delicate
that is what I am trying to do
since I am new I had toi start at the beginning
but as I go learning the language changes
by the time I get to where I am say 2.0 it is 3.0 then the same for 3.5 now 4.0
I understand what the classes are
How they continue to change the way they are declared is another story
or that is a misconception on my part perhaps
I may be missing some small step each time I go a different route
but I am asking in this instance what is the easiest way to declare?
That I will be able to use for each of these actions?
Perhaps I am not communicating properly.
I can make it all Objects then use Linq to bring them with the string builder yes?
Or bypass all of that and use Linq alone but I am reading somewhere that will inhibit other methods I may need to use.
Or Am I mistaken in that assumption?
Or forget Linq and do it with the earlier methods?
Hopefully I am able to communicate my dillema .
I have declared it 5 different ways to find I cannot use it like that for everything later.
Or to have it tell me that is illegal later.
The IDE or Debugger I mean.
No disrespect intended at all I appreciate any help I can Muster or direction I will read those tutorials again
But the situation or this situation is different somehow it seems
I must build the strings and then send them .
to use Linq to do that I must also convert to and from Decimal to Hex and Binary.
all of the above
I can do this operation manually but it takes time.
using Excel
I wished to make it automatic to save time.
and to make the little hex files degrade less.
in ordere to write each file and have it viable completely the computer it is on must have a deep copy
Or the Reader encoder prints a shallow copy and the response in the game is less
The computer that is writing the file needs to see it as an Array I think or record its pointers to new memory locations or it does not work as well
thus the desire for a database

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.