C#, odd problem....

Started by
2 comments, last by Ralphzehunter 19 years, 6 months ago
Here is my code: using System; using System.IO; public class Mygame { string[] weaponname = new string[10]; int[] weaponpower = new int[10]; int[] weaponend = new int[10]; int[] weaponcost = new int[10]; public static void Main() { ReadWeapons(); } public static void ReadWeapons() { TextReader tr = new StreamReader("w.dat"); int i = tr.Read(); int x = 0; while (x < i) { weaponname(x) = tr.Read(); weaponpower(x) = tr.Read(); weaponend(x) = tr.Read(); weaponcost(x) = tr.Read(); x++; } } } Done... When I try to compile, this is what it says: c:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\mscorlib.dll: error CS0011: Referenced class 'string' has base class or interface '' defined in an assembly that is not referenced. You must add a reference to assebly ''. c:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\mscorlib.dll: error CS0011: Referenced class 'int' has base class or interface '' defined in an assembly that is not referenced. You must add a reference to assebly ''. Any suggestions?
Advertisement
This compiles in .NET 2003. I created an empty console app and made some changes to your code. I think some of your environment variables may not be set up correctly.

Under options->projects->VC++ their should be some references to $(framework) directories.

Do you have any sample programs that came with your compiler that do compile correctly?

Also, I don't think the TextReader.Read() method is being used correctly. It only returns the next ascii character from the file.

//==========================================
public class Mygame
{
public static char[] weaponname = new char[10];
public static int[] weaponpower = new int[10];
public static int[] weaponend = new int[10];
public static int[] weaponcost = new int[10];

public static void Main()
{
ReadWeapons();
}

public static void ReadWeapons()
{
TextReader tr = new StreamReader("w.dat");
int i = tr.Read();
int x = 0;
while (x < i)
{
weaponname[x] = (char) tr.Read();
weaponpower[x] = tr.Read();
weaponend[x] = tr.Read();
weaponcost[x] = tr.Read();
x++;
}
}
}
}
I would say that it seems like you're missing a reference to system.dll - check under your references, you may have deleted it somehow.
thanks for your replies, guys : ).... i dunno what was wrong
my comp got a virus earlier this week that screwed up windows, so i had to format my hd :(.... But now when i compile my code, it works. BTW, thanks about that textreader.read part : )

This topic is closed to new replies.

Advertisement