How to set non-static variable in static method within class
    Sam Hu 
    samhu.samhu at nospam.com
       
    Thu Nov 19 00:37:16 PST 2009
    
    
  
Greetings!
How to set value to non-static variable in a static method within a class?
Given below code:
import std.stdio;
class InputDialog
{
	string name;
	
	static string s_name;
	
	static this()
	{
		s_name="";
		
		
		
	}
		
	static string getString(string prompt="Please enter a line of string below",
							string defaultValue="your string here")
	{
		defaultValue=dataFromConsole();//console input
		s_name=defaultValue;
		return s_name;
	}
	
}
int main(string[] args)
{
	string str=InputDialog.getString;
	writefln("You entered %s",str);
	
	return 0;
}
This works.But what if actually I want to set non-static variable name other than static variable s_name in static method getString(...)?
How can I do that?
Thanks for your help in advance.
Regards,
Sam
    
    
More information about the Digitalmars-d-learn
mailing list