Public Constants

  • Thread starter Thread starter jeff
  • Start date Start date
J

jeff

Hi,

what is a good way to implement public common constants. like what we do in
a common header file in C++.

jeff
 
The c# compiler try to impose OO and dont let you declare variables if
they arnt member of class, delegate, enum, interface, or struct.

you can declare the constans as static readonly members :

public class Consts
{
public static readonly string MyName = "natty";
}

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 
Hi Guys,

Here is my suggestion and how I did it in VB :
1-Create a new Class Library project in VB
2-Delete the default class file
3-Add a new module
4-Here is code of module
Public Module Module1
Public Const MY_CONSTANT As String = "FDSFSD"
End Module
5-Compile the new project called constants2, which will give me a dll
(constants2.dll)
6-Create a new project called Test_constant
7-Add the constants2.dll in the bon directory of project Test_constant and
add reference to constants2.dll
9-And in page load of the starting page of Test_constant
Label1.Text = constants2.Module1.my_constant

And label shows "FDSFSD". So it seems to work.

I have not tried it but I beleive we can also put the dll in the GAC to
share it with all the applications.
 
Back
Top