Global variable type, how to get to it?

Posted on 2009-12-19
Medium Priority
Last Modified: 2012-05-08
Hello experts :-)

I have Delphi background and I am new to C#.

In Delphi I used to create special file where I kept all my global variable types. Then I used them across my different applications and in different classes within the same application.

Now I try to do the same in C#.

1. Is it a good idea in C#?

My current approach in C# is:

- I created new file
- in this file I created namespace, static class, and static field within my static class.
Now I try to get to it from other files. How can I do it?

I am C# newbie so please explain it to me in really simple manner :)


Question by:panJacek
  • 3
  • 2
LVL 30

Expert Comment

by:Reza Rad
ID: 26087843
It is good idea to use static class,
this link has good explanation also good example for you:

let me know if you had problem on understanding it

Author Comment

ID: 26089542
To reza_rad:

Thank you for your answer.

The problem is that I still do not know how to use static class from my namespace from another files or applications.

LVL 30

Expert Comment

by:Reza Rad
ID: 26089563
ok, let me bring a simple example for you :
suppose you have a static class:

namespace MySolution
   public static class Config
      public static string CompanyName="MyCompany";

then you want to use this in other parts of your code like this:

in fact you don't need any new keyword when you want to use static class, does it make sense to you or not?

Author Comment

ID: 26089635
To reza_rad:

It makes sense but it is not what I have problem with.

My problem is to use "MySolution.Config.CompanyName" within some method placed IN ANOTHER FILE.

LVL 30

Accepted Solution

Reza Rad earned 2000 total points
ID: 26089666
>>My problem is to use "MySolution.Config.CompanyName" within some method placed IN ANOTHER FILE.
there is no problem, you can use this code in any file you want,
but if this file exists in another .net project then you must first add reference the project which has confing file , in second project
if all files in one project , you have no problem.
Did you tried this? did you got any error?

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question