Hi everyone,
I've been using Visual Basic vs MySQL, and for a lot of reasons I need to migrate to C# and still using MySQL.
In this highway I'm doing fine, but there's one thing I want you to help me:
In Visual Basic I have a module (not a class module) called functions.bas. It has all my global variables and declarations plus different purpose functions that I call from any of the forms I have.
I'd like to have the same thing in C#. Now, this is my question: is there a way to create a module (like VB 6.0) or do I need to create a class and instantiate it to access my global variables and functions?
Or
is there another way to do this that you recommend me?
Do you have any other recommendations and tips?
I'm just starting to learn C#, so actually I'm newbie yet.
Thanks for your help and time.
Loading
rolandpishPosted Aug 3, 2005, 2:51 PM
Regards
Roland
Mihir SolankiPosted Aug 3, 2005, 12:52 PM
Well if its a just standalone methods then have it as static member as there is no need of creating a instance of a class which does not offer anything. i.e System.IO.File is having all static members as it is very generic utility class.
rolandpishPosted Aug 3, 2005, 12:37 PM
Which one of the approaches is better (or recommended)?
Have a class and instantiate it -or- emulate the module concept in C#?
Thanks for your time!
Mahesh ChandPosted Aug 3, 2005, 12:23 PM
Mihir SolankiPosted Aug 3, 2005, 12:22 PM
class Global{
public static string field1 = "Field1";
protected static string _property1 = "Property1";
public static string Property1 {
get { return _property1; }
set { _property1 = value; }
}
public static void Print(string str){
// print it
}
}
Now you can use any of this member (method/property/field) just by referring it as classname.memberName i.e
Global.Print("My Message"); will print something
and you can see you dont need to create a instance of this class and you can use is globally