Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2005

Tip: Looking for answers? Try searching our database.

project level scope declaration in C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Information - 14 Sep 2005 23:10 GMT
Dear Friends,

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.

Thanks
kdsv
Jon Skeet [C# MVP] - 14 Sep 2005 23:20 GMT
> In VB.NET you can declare something like following..
>
[quoted text clipped - 8 lines]
>
> 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.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Brad Bellomo - 30 Sep 2005 21:12 GMT
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.DoThis(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.DoThis();
}

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?

> > In VB.NET you can declare something like following..
> >
[quoted text clipped - 17 lines]
> this though - constants, and public static properties are fine, but
> variables themselves don't give you much control.
Jon Skeet [C# MVP] - 30 Sep 2005 22:24 GMT
<=?Utf-8?B?QnJhZCBCZWxsb21v?= <Brad
Bellomo@discussions.microsoft.com>> wrote:
> This is my biggest dislike of C# and Java vs C++, VB and most anything else.

Well, Java 1.5 has import static which does exactly what you're after.
In my experience it's handy in certain situations (particularly for
enums), but shouldn't be used particularly often.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Mattias Sjögren - 14 Sep 2005 23:32 GMT
>Similarly I want to do it in C#.NET.

Just add a public static field or property to class. The only
difference is that you have to include the class name to reference the
member, it will not auto-import like VB Module members do.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Information - 15 Sep 2005 14:21 GMT
Thanks a lot guys.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.