Reputation: 23
OK, let me preface this by saying I'm not coding in visual studio. I'm doing this in down time at work, and don't have that option. I'm coding in Notepad ++ portable and compiling with the windows built in c# compiler.
That said, I have this class in useful.cs
using System;
public class Useful
{
public void GetInt()
{
string s = Console.ReadLine();
int i = Convert.ToInt32(s);
return i;
}
}
Now I also have a main project file, let's call it project.cs. How do I call useful.cs in that file so I can just type like int a = Useful.GetInt();
and have it work?
Upvotes: 1
Views: 1716
Reputation: 918
You should set GetInt as a static method.
public static int GetInt()
{
string s = Console.ReadLine();
int i = Convert.ToInt32(s);
return i;
}
Upvotes: 2