-2
public class Game1 : Microsoft.Xna.Framework.Game
{      
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;

     public Game1()
     {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
     }

     protected override void Initialize()
     {                
        base.Initialize();
     }

     bool hasJumped = true;            
     Vector2 velocity;
     Texture2D player;
     Texture2D ground1;
     List<Vector2> vectors = new List<Vector2>();
     List<int> list = new List<int>();
     List.add(1);

List.add(1); result in 2 errors "Invalid Token '(' in class,struct,or interface member declaration" and "using the generetic type 'System.Collections.Generic.List<T>' requiers 1type arguments"

What is going on please tell me

sll
  • 61,540
  • 22
  • 104
  • 156
  • 1
    Please spend some time on formatting your question properly next time – sll Dec 03 '12 at 21:45
  • the problem is not about the capital L maybe i have pasted it wrong look when i type "vectors" with "v" the program does not show it as registered – Georgi Antonov Dec 03 '12 at 21:56
  • @GeorgiAntonov The program has other syntax errors. You cannot trust the IDE feedback in the presence of syntax errors. You should fix all the errors people have listed, and in future perhaps supply a more complete sample of code. Best wishes. K – Kevin A. Naudé Dec 03 '12 at 22:05

4 Answers4

3

The correct case is list.Add(1)

L.B
  • 114,136
  • 19
  • 178
  • 224
Kevin A. Naudé
  • 3,992
  • 19
  • 20
2

You should use list.Add(1) instead of List.add(1). The name of the instance is list not List, and the name of the method is Add not add. Also you can't have a method call in the body of the class but in the body of the some method within the class.

You can't have this in the body of the class:

List<int> list = new List<int>();
list.Add(1);

But you can create a List in the body and have a method like this:

List<int> list = new List<int>();
public void AddOne()
{
     list.Add(1);
}

Or you can declare a list in the body and then instantiate it in the method and call Add like this:

List<int> list;
public void CreateListAndAddOne()
{
     list = new List<int>();
     list.Add(1);
}
Nikola Davidovic
  • 8,556
  • 1
  • 27
  • 33
  • the capital letter is not the problem maybe i have pasted it wrong in my case when i write "vector" it does not show "vectors" as a registered command it shows only Vector2 Vector3 and Vector4 – Georgi Antonov Dec 03 '12 at 22:03
  • I presume that it is because of the call `list.Add(1)` (as I stated numerous times in the answer, people will get bored), the code can't be compiled so the IDE is not offering you the autocomplete for the `vectors` field. – Nikola Davidovic Dec 03 '12 at 22:09
  • y but i cant see an aswer for my problem you just say "the code can't be compiled so the IDE is not offering you the autocomplete for the vectors field." so what am i supposed to do ? or it is unknown ? – Georgi Antonov Dec 03 '12 at 22:11
  • i see now just couldnt understand why the synstaxis is so wierd in this case... ill use your public void AddOne() method thx – Georgi Antonov Dec 03 '12 at 22:15
  • I have already told you. Move the `list.Add(1)` call in some method or remove it from your code, you can find the examples in the second part of my answer. You can use fields that you declare in your class only in methods (constructors, other methods, eventhandlers etc.). – Nikola Davidovic Dec 03 '12 at 22:15
1

Instead of List.add(1) use list.Add(1);.

EDIT:

Another thing you can't use it in that way in your class, but you need to use it into a method, constructor or a property. However a solution could be:

List<int> list = new List<int>(){ 1 };
Omar
  • 16,329
  • 10
  • 48
  • 66
0

Add is not a static method.. it's an instance method.

Renaming your variable will help ease the confusion (remember, C# is case-sensitive):

List<int> myIntegerList = new List<int>();
myIntegerList.Add(1);
Simon Whitehead
  • 63,300
  • 9
  • 114
  • 138
  • i have this List vectors = new List(); why when i write "vector" it shows "Vector2" "Vector3" "Vector4" but not "vectors" after it is registered above ? – Georgi Antonov Dec 03 '12 at 22:06