chapter two

2 C# Datatypes & Variables

 

This chapter covers

  • What are variables in C#
  • Variable types
  • Variable datatypes
  • The Random.Class and its types
  • Concatenation
  • Generating and displaying a random number

After section 1, we learned about the technology, whether it is the correct option for us or not, and finally, to start our first project. "Hello World!" served us well to understand how the process works, from writing our first line to seeing a result in our console. Now, we need to learn about the building blocks that make up our code.

In this chapter, we will be learning about the development process of a random number generator. Each time we run the script, a random number between two preset values is displayed. This little algorithm will aid us to understand the use of variables, the numerous datatypes that will be needed, how to generate a random value between two values, and finally, how to display our final value with a console write.

As we can see, we will be gradually increasing the difficulty from basic scripts to complex, but still tiny, algorithms.

We will be needing every bit of learning for the chapters ahead, so let us start with the second project in this book, "A random number".

2.1 Variables in C#

2.1.1 Static variables.

2.1.2 Instance variables.

2.1.3 Array variables.

2.1.4 Value parameters.

2.1.5 Reference parameters.

2.1.6 Output parameters.

2.1.7 Local variables.

2.2 The different datatypes

2.2.1 Int (Integral numeric types)

2.2.2 Float (Floating-point numeric types)

2.2.3 Char (Unicode UTF-16 character)

2.2.4 Bool (Boolean value)

2.2.5 The C# built-in value types

2.2.6 The C# built-in reference types

2.3 The random class

2.3.1 Generating different types

2.4 A random number

2.4.1 Our project

2.4.2 Our algorithm

2.5 Summary