c# equal to vb module

M

moondaddy

I'm writing a c# 3.0 app and want to know if there is anything similar to
the vibe module. I want to cache some data in memory for all classes to
access during the app session which will avoid having to access the data
source each time its needed. this data is mostly static for the session.
As I understand, a static class can not hold class level variables. I want
to create an instance of a class, have it read this data into class level
variables, then any class in the project can access this instance and
thereby not having to create new instances making them read from the data
source over and over again.

Is this possible?
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

moondaddy said:
I'm writing a c# 3.0 app and want to know if there is anything similar to
the vibe module. I want to cache some data in memory for all classes to
access during the app session which will avoid having to access the data
source each time its needed. this data is mostly static for the session.
As I understand, a static class can not hold class level variables. I want
to create an instance of a class, have it read this data into class level
variables, then any class in the project can access this instance and
thereby not having to create new instances making them read from the data
source over and over again.

Is this possible?

C# does not have module.

But take a look at singleton pattern.

Arne
 
M

Mattias Sjögren

I'm writing a c# 3.0 app and want to know if there is anything similar to
the vibe module.

A static class is as close as it gets. The difference is that module
members are automatically imported to the global namespace in VB, and
they are implicitly Shared/static (whereas C# forces you to still mark
each member as static). The end result is largely the same though.

As I understand, a static class can not hold class level variables.

Only static variables.


Mattias
 
S

Steven Cheng[MSFT]

Hi Moondaddy,

The VB.NET module come from the VB6 module which provides global shared
functions among the application. For .NET application developing through
C#, if you also want such public shared functions or variables as in VB.NET
module, you can consider define some public class with static member
variables/functions. Thus, those functions and variables can be visible and
accessible from other class code. And since they're marked as static, the
shared scope is the entire AppDomain. At runtime each AppDomain will has a
single copy of such static class variables.

If you have any further questions or concern, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi Moondaddy,

Have you got any further idea on this issue or do you have any other
questions? If there is any else we can help, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top