Exercises
1. Install and make yourself familiar with Microsoft Visual Studio and Microsoft Developer Network (MSDN) Library Documentation.2. Find the description of the System.Console class in the standard .NET API documentation (MSDN Library).
3. Find the description of the System.Console.WriteLine() method and its different possible parameters in the MSDN Library.
4. Compile and execute the sample program from this chapter using the command prompt (the console) and Visual Studio.
5. Modify the sample program to print a different greeting, for example "Good Day!".
6. Write a console application that prints your first and last name on the console.
7. Write a program that prints the following numbers on the console 1, 101, 1001, each on a new line.
8. Write a program that prints on the console the current date and time.
9. Write a program that prints the square root of 12345.
10. Write a program that prints the first 100 members of the sequence 2, -3, 4, -5, 6, -7, 8.
11. Write a program that reads your age from the console and prints your age after 10 years.
12. Describe the difference between C# and the .NET Framework.
13. Make a list of the most popular programming languages. How are they different from C#?
14. Decompile the example program from exercise 5.
Solutions and Guidelines
1. If you have a DreamSpark account (www.dreamspark.com), or your school or university offers free access to Microsoft products, install the full version of Microsoft Visual Studio. If you do not have the opportunity to work with the full version of Microsoft Visual Studio, you can download Visual Studio Express for free from the Microsoft web site; it is completely free and works well for educational purposes.2. Use the address given in the ".NET Documentation" section of this chapter. Open it and search in the tree on the left side. A Google search will work just as well and is often the fastest way to find documentation for a given .NET class.
3. Use the same approach as in the previous exercise.
Chapter 1. Introduction to Programming 109
4. Follow the instruction from the Compiling and Executing C# Programs section.
5. Use the code from the sample C# program from this chapter and change the printed message.
6. Find out how to use the System.Console.Write() method.
7. Use the System.Console.WriteLine() method.
8. Find out what features are offered by the System.DateTime class.
9. Find out what features are offered by the System.Math class.
10. Try to learn on your own how to use loops in C#. You may read about for-loops in the chapter “Loops”.
11. Use the methods System.Console.ReadLine(), int.Parse() and System.DateTime.AddYears().
12. Research them on the Internet (e.g. in Wikipedia) and take a closer look at the differences between them. You will find that C# is a programming language while .NET Framework is development platform and runtime for running .NET code. Be sure to read the section “The C# Language and the .NET Platform” form this chapter.
13. Find out which are the most popular languages and examine some sample programs written in them. Compare them to C#. You might take a look at C, C++, Java, C#, VB.NET, PHP, JavaScript, Perl, Python and Ruby.
14. First download and install JustDecompile or ILSpy (more information about them can be found in the “Code Decompilation” section). After you run one of them, open your program’s compiled file. It can be found in the bin\Debug subdirectory of your C# project. For example, if your project is named TestCSharp and is located in C:\Projects, then the compiled assembly (executable file) of your program will be the following file C:\Projects\TestCSharp\bin\Debug\TestCSharp.exe.
0 Comments