Forum C# Some C# syntax questions

Some C# syntax questions

Postby sidwoo » November 26th, 2010, 12:37 pm

Hi,

i am an AS3 developer trying to learn C#.
i found some stuff in the example codes that i didn´t understand ://

What does the "<Player>" mean?
Code: Select all
public class GameCode : Game<Player> {


Also strange Syntax for me ("private Tile[,] field " ... does it mean it´s an Array of Tiles? What does the "[,]" mean?
Do you have to specify what kind of Objects an Array consists of in C#?
Code: Select all
private Tile[,] field = {
            {new Tile(),new Tile(),new Tile()},
            {new Tile(),new Tile(),new Tile()},
            {new Tile(),new Tile(),new Tile()}
        };



thx :)
sidwoo
 
Posts: 13
Joined: November 23rd, 2010, 5:45 pm

Re: Some C# syntax questions

Postby Oliver » November 26th, 2010, 2:40 pm

Hello there, and welcome ;)

The <Player> means that the Game class will use the 'Player' class as it's player class. You could have it say "<MyPlayerClass>" and then that would be the class of the player. What it really is, is c# generics, which is a way of writing code that is strongly typed. That is, all code inside the game class KNOWS that the class of the player object so there is no need to cast it all the game. Y

It's the same with arrays. You could have an array of objects, which would be similar to an array in as3, but it's much more likely that you'll have an array with items of a specific type. Then you don't have to cast the items yourself, and the compiler does a bunch of checks for you and it's faster ;)

The [,] means that it's a Mutidimensional Array, which a C# construct for putting arrays in arrays, which i heard some people seem to enjoy. http://msdn.microsoft.com/en-us/library/2yd9wwz4(VS.71).aspx

Hope this helps a little.

Best,
Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Some C# syntax questions

Postby sidwoo » November 26th, 2010, 3:42 pm

great, thx alot :)
sidwoo
 
Posts: 13
Joined: November 23rd, 2010, 5:45 pm


Return to C#



cron