IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
C#
Search C# Group:

Advanced
-Collapse +Expand C# To/From
To/FromCODEGuides
-Collapse +Expand C# Study Test
PRESTWOODCERTIFIED
-Collapse +Expand C# Store
PRESTWOODSTORE

Prestwood eMagazine

August Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingC#Tool Basics   Print This     

All Groups:

Next Random Article Next Random Tidbit || Narrow Topic

Random Tidbit

Part of the mo. lesson in the Feb 10 Issue of Prestwood eMag
C# Code Snippet:
 A flashcard from our C# Flashcards Library
 A code snippet from our C# Code Snippets Page
 Tags: C# , Constants
C# Constants (const)

In C#, you define constants with the const keyword.

All constants are part of a class (no global constants) but you can make a constant public and have access to it so long as you have added the class to the project (even without creating the class as if they were static, but you cannot use the static keyword).

Constants must be of an integral type (sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, bool, or string), an enumeration, or a reference to null.


public class Convert : Object
{
  public const string kName = "Mike";
 
  //You can declare multiple of the same type too:
  const Double kFeetToMeter = 3.2808, kMeterToFeet = .3048;
}

More Info

Definition:  Computer Language Constants

Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1102A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile


Linked Certification Question(s)

The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

Beginner

1 Beginner Level Question

Question #1: Multiple Choice

Which statement best describes C# constants?

Answer:
1. 

Declare constants with the const keyword. All constants are part of a class (no global constants) but you can make a constant public and have access to it using ClassName.ConstantName.

2. 

Declare constants with the literal keyword. All constants are part of a class (no global constants) but you can make a constant public and have access to it using ClassName.ConstantName.

3. 

Declare constants with the const keyword. For global constants, you can make use of a special global _CSGlobal class.

4. 

Declare constants with the const keyword. You can make constants part of a class or global to a namespace using the global keyword.


 KB Article #101803 Counter
10826
Since 1/13/2009
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2020 Prestwood IT Solutions.   [Security & Privacy]