www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons C# Datatypes 2 Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
In the previous lesson we learned about the different kinds of data types, that are available in C#. In this lesson we will continue our discussion on the primitive data types of C# programming language. Their usage is pretty straight forward and the same as you are used to in C++ and Java. However you also need to know the following:

  • Unlike C++, in C#, Boolean values do not convert to integers and Boolean values (true, false) do not equate to integer variables. Thus, you may not write:

    if ( someFuncWhichReturnsAnIntegerValue() )

  • Like Java, C# supports implicit widening conversion only. For narrowing conversion, for example from float to int, the programmer has to explicitly state his intentions.
  • We we declared a variable in C and C++, it contained a random value until we assigned a value to it. This was a big source of bugs in C and C++ programs, where we accidentally tried to use a variable without first assigning it a valid value. Fortunately C# does not allow this. You must assigne a valid value to a variable before trying to use the same, or your program would not compile. This requirement or rule is also called Definite Assignment Rule.
C# Variable naming conventions:
  • You should not start a variable name with an underscore(_).
  • You should not create variable names that differ only by case. For example, it is not recommended to create name and Name as variables, simulteneously in a piece of code. It is confusing, too.
  • You should start the variable name with a lower case letter and in a multiword variable name start the second and each subsequent word with an uppercase letter. This is also called camelCase notation.
Please note that the above are just recommendations, but it is good if you follow them, as many experienced C# programmers do. The first two are compulsory only if you are writing programs that are to interoperate with other .NET languages, such as Microsoft Visual Basice.NET.
Next >>> Lesson No. 7: C# Loops

Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.