This is my biggest dislike of C# and Java vs C++, VB and most anything else.
I don't want to see global variable added to C#. However I really really
really would love something in the language that lets me treat static members
and functions of a class as if they were in the current scope.
This is purely for reason of saving the amount of typing I do (both speed of
development, and readability). For example, I want to just type:
x = DoThis(n);
Instead of:
x = MyLibrary.DoThi s(n);
If I have a lot of code and frequently use utility functions accross my app,
this really is a lot of typing I have to do in C# that I would not have in
C++. Yes, I know I can just add a function to the class I am working on:
static int DoThis(int x)
{
return MyLibrary.DoThi s();
}
but it is a pain to do this all the time for every class and library
function I use often.
How about a feature like putting
using globalscope = MyLibary;
at the top of my class?
"Jon Skeet [C# MVP]" wrote:
Information <ku******@gmail .com> wrote: In VB.NET you can declare something like following..
Module modVar2
Public sb as String
End Module
Now, sb is a project level scope variable and can be accessed any where
in the project.
Similarly I want to do it in C#.NET.
Any help would be appreciated.
public class ModVar2
{
public static string sb;
}
It's generally not a good idea to have actual global variables like
this though - constants, and public static properties are fine, but
variables themselves don't give you much control.
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too