Beginner Question. What does the > mean? Not greater than.

N

needin4mation

I was looking at this code, and have seen it in other code (like it):

/// <summary>
/// Bitmap font class for XNA
/// </summary>
public class BitmapFont
{
private SpriteBatch m_sb;
private Dictionary<int, BitmapInfo> m_dictBitmapID2BitmapInfo;

and like:

m_dictBitmapID2Texture = new Dictionary<int, Texture2D>(); //what's
the paren mean too?

What does the < > mean? What do I search on to understand what the
angle bracket symbols mean in a context like this? Thank you for any
help.
 
T

Truong Hong Thi

It is Generics syntax, a new feature of .NET v2.0.
Check out C# 2.0 documentation.
 
J

Joanna Carter [TeamB]

<[email protected]> a écrit dans le message de (e-mail address removed)...

| What does the < > mean? What do I search on to understand what the
| angle bracket symbols mean in a context like this? Thank you for any
| help.

private Dictionary<int, BitmapInfo> m_dictBitmapID2BitmapInfo;

This indicates that a generic Dictionary class is being "bound" to int, as
the key, and BitmapInfo, as the value, types.

Previously, to create a dictionary in .NET1.1, you would have had to use a
Hashtable and cast both the key and value to/from their real types to
System.Object. A generic class allows you to declare a class that can work
with many different types; in situations where the code remains the same,
only the type changes.

This is especially efficient because any operation that casts a value type
like an integer to System.Object also involves a boxing operation. Generic
classes like List<T> allow binding directly to the integer type as in
List<int> to give you a list of integers that is typesafe and that does not
incur any boxing/casting penalty when adding/retrieving items.

Joanna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top