Hello!
I have a method in a public class
static void Input ()
{
// Coding here
}
and I was wondering if it is possible for me to call that static method over to another class.
I tried this:
Input inp = new Input( );
inp.Start();
but it doesn't seem to work (The type or namespace name "Input" could not be found).
Ramesh MaruthiPosted Oct 14, 2014, 9:53 PM
Ramesh MaruthiPosted Oct 15, 2014, 3:26 PM
Song LeePosted Oct 15, 2014, 3:24 PM
I got it now~! XD
Rajeev RanjanPosted Oct 15, 2014, 12:43 AM
Static member gets called when the instance of the class is created, and it is accessed by the class name rather then creating object and "object.InstanceName".
Try to call directly
Jignesh TrivediPosted Oct 15, 2014, 12:09 AM
Hi,
The static member (methods, fields, properties, or events) is callable on a class even when no instance of the class has been created. The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created.
you have to use
Input.Start();
hope this will help you.
Song LeePosted Oct 14, 2014, 8:05 PM
public class Input
{
static double fromF;
public void Start()
{
FirstInput();
}
static void FirstInput()
{
Console.Write("Enter number : ");
double.TryParse(Console.ReadLine(), out fromF);
}
///////////////////////////////////////////////////////////////////////////
I need this method called to another class.
it's so~ confusing because i am not sure if Static void FirstInput() needs to be double or string.
Ramesh MaruthiPosted Oct 14, 2014, 6:35 PM