Nezmyselné chyby vo Visual C# Express
Nezmyselné chyby vo Visual C# Express
Ahojte, začal som programovať v C# spolu s frameworkom XNA, avšak mám jeden problém. Začal som na jednom projekte, projekt bol funkčný, neboli v ňom žiadne chyby, projekt som uložil a na druhý deň keď som ho otvoril tak v jednom súbore bolo 14 chýb. Prezrel som celý kód avšak bol v poriadku, v rovnakom stave ako pred uložením, skúšal som preinštalovať visual express, no nepomohlo. Kamarát tiež programuje v C# aj s XNA frameworkom, tak som mu poslal celý solution, no keď ho otvoril, tak žiadne chyby tam neboli, ako je toto možné? Mimochodom toto sa mi stalo už 2. krát, avšak mal som veľmi málo kódu napísaného, tak som solution vymazal a naprogramoval som to celé ešte raz, ale čo ak raz keď bude projekt v takom stave že sa to nebude dať?
Re: Nezmyselné chyby vo Visual C# Express
Ono by dost pomohlo, keby si nam napisal o ake chyby sa jedna.
Re: Nezmyselné chyby vo Visual C# Express
Takže tuto je kód v tom súbore kde sú chyby, chyby som dal do komentov k jednotlivým riadkom
Spoiler
Kód: Vybrať všetko
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using The_Destiny_of_Azureus.Komponenty;
namespace The_Destiny_of_Azureus
{
public class Hra : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
public SpriteBatch spriteBatch;
public int wwidth = 1366;
public int wheight = 768;
Texture2D cursor;
MouseState mouseState;
public Hra()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
graphics.PreferredBackBufferWidth = wwidth;
graphics.PreferredBackBufferHeight = wheight;
graphics.IsFullScreen = false;
graphics.ApplyChanges();
MMenu mmenu = new MMenu(this);
Components.Add(mmenu); //1 chyby:
//} expected,
public Button ngbutton = new Button(this, new Vector2(64, 258), "NEW GAME"); // Keyword 'this' is not available in the current context
Components.Add(ngbutton); //3 chyby:
//Invalid token '(' in class, struct, or interface member declaration,
//Invalid token ')' in class, struct, or interface member declaration
//Microsoft.XNA.Framework.Game.Components is a property but is used like a type
base.Initialize(); //1 chyba: Method must have a return type
}
protected override void LoadContent() //1 chyba: Expected class, delegate, enum, interface, or struct
{
spriteBatch = new SpriteBatch(GraphicsDevice); //1 chyba: Expected class, delegate, enum, interface, or struct
cursor = Content.Load<Texture2D>(@"Textury\cursor");
}
protected override void UnloadContent() //1 chyba: Expected class, delegate, enum, interface, or struct
{
}
protected override void Update(GameTime gameTime) //1 chyba: Expected class, delegate, enum, interface, or struct
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
mouseState = Mouse.GetState();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime) //1 chyba: Expected class, delegate, enum, interface, or struct
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(cursor, new Vector2(mouseState.X, mouseState.Y), Color.White); //1 chyba: Expected class, delegate, enum, interface, or struct
spriteBatch.End();
base.Draw(gameTime);
} //1 chyba: Type or namespace definition, or end-of-file expected
}
}
Re: Nezmyselné chyby vo Visual C# Express
Niekde tam musí chýbať ;, prípadne je tam { naviac. BTW sú to IntelliSense chyby alebo chyby pri kompilácii? Pokým je toto tu naozaj súbor čo kompiluješ, tak by kompilátor chyby nemal nájsť.
Re: Nezmyselné chyby vo Visual C# Express
No písal som na stackoverflow a bol a tam jedna primitívna chyba - vo funkcii intialize(), tento riadok
stačilo dať preč public 
Kód: Vybrať všetko
public Button ngbutton = new Button(this, new Vector2(64, 258), "NEW GAME");