And at the highest level, the general managers control the various aspects of the manufacturing processes in the factory. The essence of programming is to control the work of the computer at all levels. The architecture of the software – for example, single-tier, dual-tier, triple-tier, multi-tier or SOA architecture;.
The number and skills of people who will be part of the development team (big and serious projects are done by large and experienced teams of developers); Methods are nested within the class definition (move to the right by one or more characters [Tab]);
The C# Language and the .NET Platform
The C# Language
Independence from the Environment and the Programming Language
A major advantage of .NET technology is the ability to run code that is written and compiled only once, on different operating systems and hardware devices. An example of .NET implementation for non-Windows environment is the open source project Mono (www.mono-project.com). It implements the .NET Framework and most of its bundled libraries for Linux, FreeBSD, iPhone, and Android.
Microsoft Intermediate Language (MSIL)
We can compile a C# program in a Windows environment and then run it under Windows, Windows Mobile, Windows RT or Linux. Microsoft officially only supports the .NET Framework on Windows, Windows Mobile, and Windows Phone, but there are third-party vendors that offer .NET implementations on other operating systems. It implements the main .NET standards well (such as the C# compiler and CLR), but does not fully support the latest .NET technologies and framework such as WPF and ASP.NET MVC.
The .NET Platform
NET Technologies
There are general software technologies, such as web technologies, mobile technologies, computer graphics technologies, and technologies related to a particular platform such as .NET or Java. Another example is the library that deals with networking (System.Net). It has built-in functionality to send emails (using the System.Net.Mail.MailMessage class) and to download files from the Internet (using System.Net .Web client). A .NET technology is the collection of .NET classes, libraries, tools, standards and other programming resources and established development models, which define the technological framework for creating a particular type of application.
For example, ADO.NET is a technology that provides a standardized approach to accessing relational databases (such as Microsoft SQL Server and MySQL). The classes in the System.Data.SqlClient package (namespace) are an example of the .NET library, which provide functionality to connect to a SQL Server through ADO.NET technology. Some of these are noticed by Microsoft and later added to the next iteration of the .NET Framework.
In this way, the .NET platform is constantly evolving and expanding with new libraries and technologies. And this is how the LINQ-to-SQL and ADO.NET Entity Framework technologies were born, in .NET 3.5 and .NET 4.0 respectively. As an example we can look at the .NET API itself; it is a set of .NET class libraries, which extend the capabilities of the language and add high-level functionality.
It is publicly available on the Internet and is also distributed with the .NET platform as a collection of documents and tools for browsing and searching.
What We Need to Program in C#?
The MSDN Library is Microsoft's official documentation for all of their products for software developers and technologists.
Compilation and Execution of C# Programs
It is recommended that you run the console as an administrator (right-click the Command Prompt icon and choose 'Run as administrator'). This is a common problem and it is normal for it to occur if it is the first time we use C#. The .NET Framework is installed correctly, but the Microsoft.NET\Framework\v4.0.xxx folder is not added to the system path for executable files and Windows cannot find csc.exe.
The first problem is easily solved by installing the .NET Framework (version 4.5 in our case). The second problem can be solved by changing the system path (we will do this later) or by using the full path to csc.exe as shown in the image below. In our example, the full file path to the C# compiler is C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe (note that this path may vary depending on the installed version of the .NET Framework).
After execution, csc completes without errors and as a result we get the following file: C:\IntroCSharp\HelloCSharp.exe. The result of executing our program is the message "Hello, C#!" printed on the console. If we know how to use the C# command line compiler (csc.exe) without entering the full path to it, we could add its folder to the Windows system path.
To do this, we open a new cmd.exe (Command Prompt) window (it is important to restart the Command Prompt) and type the "csc" command.
Visual Studio IDE
Adding additional paths to those already existing in the Path environment variable is done by concatenating the path name with the others and using a semicolon (;) as a separator. We must be careful because if we delete any of the existing system paths, some of the Windows functions or some of the installed software may fail to work properly.
Integrated Development Environments
What Is Visual Studio?
Start page – from the start page we can easily open any of our latest projects or start a new one, to create our first C# program or get help on how to use C#. We learn how to use this window later when we compile C# programs in Visual Studio. Solution Explorer – when no project is loaded, this window is empty, but it will become a part of our lives as C# programmers.
It will show the structure of our project – all the files it contains, whether they are C# code, images, or any other type of code or resources. There are many other helper windows in Visual Studio, but we will not go over them at this time.
Creating a New C# Project
Data is entered using the keyboard, and when the result needs to be printed, it is displayed on the console (as text on the screen in the program window). In addition to console applications, we can build applications with a graphical user interface (eg Windows Forms or WPF), web applications, web services, mobile applications, Windows Store applications, database projects and others. It is very important to give your files, classes, methods, and other program elements meaningful names so that they can be easily found and navigated through your code.
A meaningful name means a name that answers the question "what is the purpose of this file / class / method / variable?" and helps developers understand how the code works. If your project is named well, after a few months or a year you'll be able to explain what it's intended to do without opening it up and looking inside. To rename the Program.cs file, right-click on it in Solution Explorer and select "Rename".
A dialog box will appear asking us if we want to rename both the class name and the file name. If not, we double-click the HelloCSharp.cs file in the Solution Explorer to load it.
Compiling the Source Code
Starting the Project
It's a reminder from Visual Studio that our program has finished executing, giving us time to see the result. If we run the program by pressing [F5] only, that message will not be displayed and the result will disappear immediately after it is displayed because the program will have finished its execution and the window will be closed.
Debugging the Program
To execute, a C# project must have one class with a Main() method declared in the manner described earlier in this chapter. We move the cursor to the line with the opening parenthesis in the Main() method and press [F9] (by doing so we place a breakpoint on that line). The line will be colored yellow and we can execute the program step by step.
When we are on a given line and it is colored yellow, the code on that line has not yet been executed. Once we know where exactly the problem is in the program, we can easily fix it. To do this, we must first stop the execution of the program before it finishes.
Then we delete the problem line and start the program in normal mode (without debugging) by pressing) [Ctrl+F5].
Alternatives to Visual Studio
SharpDevelop
MonoDevelop
Decompiling Code
We want to check how a certain algorithm is implemented, but we don't have the source code, e.g. There are several options when using a .NET library, and we want to find the optimal choice. We want to see how we can use certain APIs by digging into some compiled code that uses them.
We don't have information on how a particular library works, but we do have compiled code (.NET assembly) that uses it, and we want to find out exactly how the library works. The first popular .NET decompiler was Red Gate's Reflector (before it went commercial in early 2011). Another good decompiler tool for .NET is ILSpy, which is developed around the SharpDevelop project.
For example, if we want to see how the static method System.Currency.ToDecimal works, we can first use the tree on the left to find the Currency class in the System namespace and finally select the ToDecimal method. Unfortunately, the version at the time of writing this book (ILSpy 2.1) can only decompile the languages C#, VB.NET and IL. JustDecompile and ILSpy are extremely useful tools, which can help almost every day in .NET software development and we should definitely download at least one and play with it.
When we wonder how a certain method works or how something is implemented in a given assembly, we can always rely on a decompiler to find out.
C# in Linux, iOS and Android
Other .NET Languages
Exercises
Solutions and Guidelines
Use the System.Console.WriteLine() method