473,413 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

global constants

Hi all
I need to create some strings, constants etc. in my class
library that need to be shared across all the classes in
my class library. How do I accomplish this?

Do these strings and constants have to be embedded in a
class? Is there a better way to do this?
Thanks for your help.
Nov 15 '05 #1
5 1751
Well, you could use embedded resources, or you could just make the constants
static in some class that your operations can use.

".NET beginner" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
Hi all
I need to create some strings, constants etc. in my class
library that need to be shared across all the classes in
my class library. How do I accomplish this?

Do these strings and constants have to be embedded in a
class? Is there a better way to do this?
Thanks for your help.

Nov 15 '05 #2
Thanks Peter for your reply. what did you mean by embedded
resources? Thanks a lot for your input.
-----Original Message-----
Well, you could use embedded resources, or you could just make the constantsstatic in some class that your operations can use.

".NET beginner" <an*******@discussions.microsoft.com> wrote in messagenews:01****************************@phx.gbl...
Hi all
I need to create some strings, constants etc. in my class library that need to be shared across all the classes in
my class library. How do I accomplish this?

Do these strings and constants have to be embedded in a
class? Is there a better way to do this?
Thanks for your help.

.

Nov 15 '05 #3
Are you familiar with the concept of resources? Basically, resources can be
embedded/compiled in your application so that are actually part of the
binaries (no satellite files). This is what those .resx files are. They
get embedded in your application when the code is compiled. You can create
your own .resx files and then use classes in the ResourceManager to access
them. Honestly I have not had much experience with resources. If you do
not need culture specific constants, you might just add them as static
constants in some utility class.
<an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
Thanks Peter for your reply. what did you mean by embedded
resources? Thanks a lot for your input.
-----Original Message-----
Well, you could use embedded resources, or you could just

make the constants
static in some class that your operations can use.

".NET beginner" <an*******@discussions.microsoft.com>

wrote in message
news:01****************************@phx.gbl...
Hi all
I need to create some strings, constants etc. in my class library that need to be shared across all the classes in
my class library. How do I accomplish this?

Do these strings and constants have to be embedded in a
class? Is there a better way to do this?
Thanks for your help.

.

Nov 15 '05 #4
If you dont have any need for internationalization of your
strings i like using a nested structure of string
constants. Something like the following. Its hard to
read in the post, but just copy / paste it into your code
or notepad to see what i mean.
internal struct Constants
{
internal struct Errors
{
internal const string ErrMsgAddInName
= "CS Dev Tools";
internal const string ErrLoadingAddIn
= "Error loading Add-In: \r\n";
internal const string ErrInCodeFragMgr
= "Error in the code fragmant manager: \r\n";
internal const string ErrInsertCodeFrag
= "Error inserting code fragment into code window: \r\n";
internal const string ErrNoTextSelected
= "No text was selected in code window";
internal const string
ErrCodeFragNameExists = "Code Fragment already has this
name.\r\nPlease choose another name";
}

internal struct UndoContexts
{
internal const string ADD_FRAGMENT
= "AddFragment";
internal const string ADD_CODEREVIEW_ITEM
= "AddCodeReviewItem";
internal const string NEW_PROPERTY
= "NewProperty";
internal const string NEW_MSGBOX
= "NewMsgBox";
internal const string ADD_REGION
= "AddRegion";
internal const string ADD_REGEX
= "AddRegEx";
internal const string ADD_CONSTRING
= "AddConnectionString";
}

internal struct Kinds
{
internal const string vsViewKindCode
= "{7651A701-06E5-11D1-8EBD-00A0C90F26EA}";
internal const string vsCMLanguageVB
= "{B5E9BD33-6D3E-4B5D-925E-8A43B79820B4}";
}

internal struct OutputMsg
{
internal const string Output_Spaces = " ";
internal const string Clean_Name = "-------
--- Cleaning Solution ----------";
internal const string Clean_SavingSolution
= " 1. Saving solution all projects";
internal const string Clean_CloseSolution
= " 2. Closing solution";
internal const string Clean_DeleteFiles
= " 3. Deleting intermediate files and output files
for projects:";
internal const string Clean_ReOpenSolution
= " 4. Re-opening solution";
internal const string Clean_Building
= " 5. Building solution";
internal const string Clean_Finished
= "********** Clean finished **********";
}
}
-----Original Message-----
Hi all
I need to create some strings, constants etc. in my class
library that need to be shared across all the classes in
my class library. How do I accomplish this?

Do these strings and constants have to be embedded in a
class? Is there a better way to do this?
Thanks for your help.
.

Nov 15 '05 #5
thanks a lot Jon. That helped a lot.
-----Original Message-----
If you dont have any need for internationalization of yourstrings i like using a nested structure of string
constants. Something like the following. Its hard to
read in the post, but just copy / paste it into your code
or notepad to see what i mean.
internal struct Constants
{
internal struct Errors
{
internal const string ErrMsgAddInName
= "CS Dev Tools";
internal const string ErrLoadingAddIn
= "Error loading Add-In: \r\n";
internal const string ErrInCodeFragMgr
= "Error in the code fragmant manager: \r\n";
internal const string ErrInsertCodeFrag
= "Error inserting code fragment into code window: \r\n";
internal const string ErrNoTextSelected
= "No text was selected in code window";
internal const string
ErrCodeFragNameExists = "Code Fragment already has this
name.\r\nPlease choose another name";
}

internal struct UndoContexts
{
internal const string ADD_FRAGMENT
= "AddFragment";
internal const string ADD_CODEREVIEW_ITEM
= "AddCodeReviewItem";
internal const string NEW_PROPERTY
= "NewProperty";
internal const string NEW_MSGBOX
= "NewMsgBox";
internal const string ADD_REGION
= "AddRegion";
internal const string ADD_REGEX
= "AddRegEx";
internal const string ADD_CONSTRING
= "AddConnectionString";
}

internal struct Kinds
{
internal const string vsViewKindCode
= "{7651A701-06E5-11D1-8EBD-00A0C90F26EA}";
internal const string vsCMLanguageVB
= "{B5E9BD33-6D3E-4B5D-925E-8A43B79820B4}";
}

internal struct OutputMsg
{
internal const string Output_Spaces = " ";
internal const string Clean_Name = "-------
--- Cleaning Solution ----------";
internal const string Clean_SavingSolution
= " 1. Saving solution all projects";
internal const string Clean_CloseSolution
= " 2. Closing solution";
internal const string Clean_DeleteFiles
= " 3. Deleting intermediate files and output filesfor projects:";
internal const string Clean_ReOpenSolution
= " 4. Re-opening solution";
internal const string Clean_Building
= " 5. Building solution";
internal const string Clean_Finished
= "********** Clean finished **********";
}
}
-----Original Message-----
Hi all
I need to create some strings, constants etc. in my classlibrary that need to be shared across all the classes in
my class library. How do I accomplish this?

Do these strings and constants have to be embedded in a
class? Is there a better way to do this?
Thanks for your help.
.

.

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: mark4asp | last post by:
What are the best methods for using global constants and variables? I've noticed that many people put all global constants in a file and include that file on every page. This is the best way of...
10
by: Matt | last post by:
Greetings, What are people's thoughts on global variables in C++? Why are we taught not to use them in programming? Is it true that if you are running two copies of the C program one copy can...
20
by: 2obvious | last post by:
I've been trying to create read-only global variables by creating constants (Const) in my global.asa, but I can't seem to reference them. Sticking them in an include works fine, but it seems more...
1
by: Xiangliang Meng | last post by:
Hi, all. Recently, I find there is a way in our project to maintain a global set in many files by using preprocessing directives. I'm wondering if we could find a better method for this. Many...
25
by: Daniel Bass | last post by:
how do i declare a global variable in c#.net? it's like it want's everything in classes... there are times when globals are good, like having constants in a program which apply to several...
4
by: Amadelle | last post by:
Hi all and thanks again in advance, What is the best way of defining global constants in a C# application? (A windows application with no windows forms - basically a set of classes). Would it be...
8
by: Marty | last post by:
Hi, I'm new to C#, I used to code in VB.NET. Where is the best place to declare all my constants and global objects in my C# project to have them accessible globally? I have an event logger...
1
by: 2obvious | last post by:
I want to declare some constants on the application level in global.asax to use throughout my application, e.g.: Sub Application_OnStart() Const NUM As Integer = 5 End Sub Problem is, when I...
8
by: Thomas Coleman | last post by:
Ok, I've obviously discovered that Global.aspx has been completely changed in ..NET 2.0. However, I haven't figured out how to declare a constant that's available to any page in my application...
6
by: lazy | last post by:
hi, I have some constants defined in a php script say config.php. I want to use the variables there defined in other scripts. couple of questions regd that: 1. Is there an alternative to...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.