I am going to describe how to create a basic C# console application in which we generate a random number and then guess it.Before diving in I am just giving an introduction on C# and .NET and also which tools we will be using in building this application.
C# is an object oriented programming language created by Microsoft and it is one of the many languages used along with .NET framework. There is generally a confusion between C# and .NET, I will try to clear this. C# is basically a programming language and we use it along with .NET framework to build applications for Windows and we can also use C# to build applications for other platforms like Linux by making use of Mono, which is a open source implementation of Microsoft .NET Framework.
.NET is a framework for building windows applications and web applications and this is not limited to one language. We can use C#, VB.Net, F#, C++, J# and many more like around sixty languages. It has two important components say Common Language Run-time and Class Library. CLR is a virtual machine component and manages execution of .NET programs. Common Language Runtime or CLR is the run-time execution environment of .Net Framework. Converting MS-IL into platform or OS specific code is done by the CLR. CLR is responsible for bringing application to life and its also the CLR’s job to tear down application when its finished executing or if it has an unrecoverable error. CLR actively tracks all the memory a program uses and it knows when the program is finished with memory so it will clean things up and allows program to have enough memory as it runs.
We make use of an IDE(Integrated Development Environment) to build our application. We use Visual Studio (Community edition) as it is free.
First we should decide the algorithm on how we are writing our program. The algorithm is as follows:
1.Generate a random number .
2.Take input from user.
3.Check whether both are equal.
4.Make user know whether value he entered is greater or lesser than the secret number.
5.Continue steps 2 ,3,4 until guess is correct.
6.If user quits close or else continue from step 1 again.
Get Microsoft Visual Studio installed and Create a new project. In creating new project select Console Application and select location where you want
to save the project.
Once you click on OK you have a new screen with defaults loaded. We have a program.cs file created for us with an empty main method which is our entry point.
Now we can start writing our application. First we need to generate a random number for this we make use of Random class .
After generating this number we should prompt the user to guess a value.
Now we should check whether the guess and secret number are equal or not. We should do this until user enters the correct value.
We should allow user to play the game until he wants to quit.
now the application is done and we can start using it to play with your friends.