I.T. Discussion Community!
-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

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

   ► KBProgrammingC#Tool Basics   Print This     
  From the February 2015 Issue of Prestwood eMag
 
C# Tool Basics:
C# Case Sensitivity (Yes)
 
Posted 11 years ago on 12/31/2008 and updated 10/24/2009
C# Code Snippet:
 A flashcard from our C# Flashcards Library
 A code snippet from our C# Code Snippets Page

KB101336



Languages Focus: Case Sensitivity

Case sensitiviy in this case is referring to commands and variable names. For example, are "printf" and "PrintF" equivalent? Are fullname and FullName equivalent? When you create commands, operations, methods, or variables should you worry about case?

C# Case Sensitivity

In C# commands and variable names are case sensitive. The following does NOT:

messagebox.Show("hello");  //Does not compile!

The first time you type any other case for commands or variables, VS.Net will change it to the accepted or defined case. For example, if you type messagebox.show it is converted to MessageBox.Show. Once corrected, you can break it again by editing MessageBox to messagebox and the compiler will give you an error.

Syntax Example:

The following code works:

MessageBox.Show("hello");

Wrong Cased Variables Give Compiler Error

If you declare a variable with one case and attempt to use it with another case, you'll get a compiler error.

For example:

String MyName;
  
myname = "Felicia";   //Compiler error.
MessageBox.Show("Hello " + MyName);

Using Same Named-Different Cased Variabes

You can have the same named variable with an alternate case. Although not the best idea, the following does work:

String MYNAME;
String MyName;
  
MYNAME = "Nathan";
MyName = "Felicia";
MessageBox.Show("Hello " + MYNAME); //Shows Nathan.
MessageBox.Show("Hello " + MyName); //Shows Felicia.

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 = P1226A1
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: True or False?

In C# you can declare and use a variable spelled the same but with a different case as in the following:

Int16 InvoiceNumber;
Int16 INVOICENUMBER;
  
InvoiceNumber = 1001;
INVOICENUMBER = 1002;
  
MessageBox.Show("" + InvoiceNumber);
MessageBox.Show("" + INVOICENUMBER);
Answer:
  • True
  • False

  •  KB Article #101336 Counter
    9796
    Since 12/31/2008
    -
       Contact Us!
     
    PrestwoodBoards.com was developed and is maintainted by me. Do you have a question or suggestion? Do you see a problem? Contact me now. My goal is to build an ad-free and spam-free source of I.T. information with many contributers (ok to promote your website/company in your bio). Yes, my company Prestwood IT Solutions is mentioned in my bio which shows with every post, but you can contribute and promote your pet project too!

    2,200 People Online Now!!  
    Sign In to see who's online now!  Not a member? Join now. It's free!
    Show more stats...


    ©1995-2019 PrestwoodBoards  [Security & Privacy]
    Professional IT Services: Coding | Websites | Computer Tech