Hi welcome to this this module, introduction to C#. This is the first module in a series that will get you started with C# language and the .NET framework , and equip you with the knowledge that a C# developer requires to be productive . In this first module, we are going to talk about the .NET framework and its different components. Like for example , the CLR and the FCL which you will be using when you write your C# program. So !!! Let’s get started right away.
Rich Client AppsWeb ServicesWeb ApplicationsWindows Mobile AppsData Driven AppsDesktop ApplicationsClient Server ApplicationsWhat is the common factor amongst these apps?Well all of them can be created using the .net framework.
In this module, we are going to talk about the .NET framework and its different components. Like for example , the CLR , common language runtime which is the heart and soul of the .net Framework ,and the Framework class library FCL which the main set of API’S that you will be using to write .net applications.We will also talk about the Common type system CTS that allows us to define different types ,as in .net everything has to have a type.Then we will discuss a little bit about the C# syntax , and about the expressions and operators used inside the program. Then we look into Visual Studio, which is a complete suite of applications created by Microsoft to give developers a compelling development environment for the Windows and .NET platforms. Then of course along the way we’ll do lots of demos, I will be using both the command line tools to build our programs, but we will also be seeing the Visual Studio side of things. That is, …uh creating a project and executable in visual studio.
OK !! So what is .net ? The microsoft .net framework is a generic software framework that the software developers can use to create applications for your Desktop or a website which you are visiting. So .Net is something that your application is going to be built on top of. .Net framework provides all the services to different type of applications that you need. For example, …uh the ability to save information in to the database, or the ability to read information from an XML file. Cryptography , Web applications, algorithms, Network communication apps , these are the type of features and services that .net is going to provide for your application.you can build a wide variety of applications on top of it .you can build web applications that produce HTML ,that the user is going to interact with through a web browser. You can also write desktop applications . You can write windows services which might run on the server in the background and the user doesn’t interact with them directly but they can do batch processing. Windows services can monitor directories and process files while they run. When you are creating an application in C# , your application is going to run on the top of .net framework . So that does means, .net framework has to be installed on the computer where you want your software to execute. It is very easy to download and install the .net framework. Some of the recent releases of Windows operating system already have .net installed. So Windows server 2010, Windows vista, Windows 7, They all come with version 3 of the .net framework. Now !!! The framework itself has two separate pieces , the common language runtime (CLR) and the framework class Library (FCL).
CLR is the main compilation and execution engine of the .net framework. It brings you application to life as it compiles and executes successfully , or , if there is an error during execution.CLR actively tracks the objects created in your code and cleans up unused ones when the program stops executing.It provides your application with security when your application does not have access to certain areas outside the sandbox. For example, the file system. CLR also makes sure that the app is not reading from or writing to memory that does not belong to you. CLR also takes care of handling the operating system version or CPU compatibility for you .This means that a specific .NET software will always run in the most efficient way , regardless of the hardware or the operating system version its running on.The CLR is also language independent. So it does not matter if you are writing code in C# or VB.Net or any other .Net compatible language. You can use any of these for writing your .Net Applications.Another aspect to note is that, …uh not only CLR is operational on any windows OS since XP, but also available on windows mobile . Although that is a different special version of CLR than the desktop machine. Silverlight applications also use the CLR. Silverlight applications run in the browser . So this version of CLR will run both on windows machine as well as Apple machine browser like Safari.
The CLR works in the background to manage your .NET application. But it is the framework class Library that we will be frequently using because it contains thousands of classes you use to build different .Net applications. The FCL is a group of APIS and classes which you can use to interact with the file system, the registry and the network.FCL provides you with all the functionality to do things like access data from the database or read from and write to file systems, use pretext and regular expressions or even , …uh use sockets. It provides system functionality and is designed to be the foundation on which .NET Framework applications, components, and controls are built.The framework class Library uses Windows presentation foundation (WPF) that allows you to create applications that run directly on the users desktops. Or ASP.NET that allows you to create web applications which the end user can use the browser to interact with. There are also classes in the Framework Class Library that use part of Windows communication foundation to read web services allows computers to communicate with others. The FCL is really very huge and It’s very rare for one person to know all the ins and outs of the library, typically you are going to focus on just a couple of pieces and master those and build applications from specific pieces you need for your business.
We have seen in the previous slide that the CLR compiles and executes code that is written in a variety of .Net compatible languages like c# or vb.net. So, how does it actually work ?Well, in .Net, the code that you write is first cimpiled by the language compiler such as c# or vb compiler to an intermediate language called CIL or Microsoft IL. And it is this IL that the CLR understands and it compiles it to native code that the platform executes. This is the major reason for CLR’s language independence.The there is the CTS or the Common Type System that each language will produce with methods ,fields, events and properties etc.The common type system defines how types are declared, used, and managed in the CLR, and is also an important part of the runtime's support for cross-language integration. The common denominator of the CLR and the CTS is the CLS or the Common language System, which is a set of basic language features needed by many applications. The CLS rules define a subset of the common type system; that is, all the rules that apply to the common type system.
Let us briefly review the architecture of .NET .As we have already discussed,The heart of .NET is the .NET Framework. The most important component of the framework is the CLR . Every application written using the Framework depends on the CLR. Among other things, the CLR provides a common set of data types, acting as a foundation for C#, VB, and all other languages that target the .NET Framework. Because this foundation is the same no matter which language they choose, developers see a more consistent environment.The CLS is a statement of rules that allow each language to interoperate. For example, the CLS guarantees that Visual Basic’s idea of an integer is the same as C#. Because the two languages agree on the format of the data, they can transparently share the data. The CLS defines not only type information, but also method calls, error handling, and so forth.You can define a class in Visual Basic and use it in C#. A method that is defined in C# can be called by Visual Basic or any other language that adheres to the CLS. After an API is learned in one language, then using that API in any other CLS-compliant language is virtually the same.The middle layer called Application Class Libraries and Services. This layer represents the rich set of libraries and APIs that have been created to support virtually all aspects of programming. Graphical user interface APIs or Windows.Forms, database APIs through ADO.NET, XML processing, regular expression handling, and so forth are all part of this layer.Visual Studio .NET is an important part of the .NET Framework because it provides a means for the programmer to access the framework at any level. A programmer can use Visual Studio .NET to write code in many supported managed languages, or he can bypass the CLR altogether and write unmanaged code with Visual Studio .NET.On the top of the figure, you can see the four languages that Microsoft has announced it will provide support for “out of the box.” The ellipsis signifies the other significant and growing set of languages that support the Common Language Specification (CLS) and are full participants in the .NET Framework. Applications written in any .NET language can use the code in the .NET Framework class library. Among the most important technologies provided in this library are the following:ASP.NET: Classes focused on building browser-accessible applications.Windows Forms: Classes for building Windows graphical user interfaces (GUIs) in any CLR-based programming language.ASP.NET Web Services (also called ASMX): Classes for creating applications that communicate with other applications using Web services.Enterprise Services: Classes that provide distributed transactions, object instance control, and other services useful for building reliable, scalable applications.ADO.NET: Classes focused on accessing data stored in relational database management systems (DBMS).
Let me quickly brief you on how C# came into being. In the 80’s ,C /C++ and Java were very popular programming languages used by programmers to build applications.C was extended to C++ with which programmers could improve the quality of code they produced and reusable code was easier to write.C# (pronounced C Sharp) is a new revision of the C language introduced by Microsoft in 2001 for the brand new .Net Framework. C# is an object orientated language heavily based on C++ with features derived from other programming languages such as Delphi and Java. Microsoft has simplified the C# language. It is not messy, is event driven, and the .Net framework removes a lot of the issues introduced by sloppy programming by using a managed environment.
C# is a standardized language for creating .net components and applications. That is because it is registered with ECMA international, whch is an internationally recognized standardization association. C# is used to create any type of .net application, services and even reusable libraries ,that is you can package the code to be used across multiple applications by creating a library. The syntax was inspired from C++ and JAVA’s syntax hence these languages look somewhat similar.
Take a look at this piece of code. This is how a simple C# program looks.Top few lines here are references to different namespaces from the .net Framework class library.A namespace is a group of classes of related functionality . And we use the using keyword to access them in our c# application .There are many important namespaces like the system which is the root namespace in the hierarchy. Everything is derived from system.We use only those namespces in the applications, which are required by our business requirementNamespace Helloworld is a good way of organising our classes. We can include multiple classes in our own namespace.Every code in .net has tobe contained in a class. In this case we have a class called program.Our program class contains a very important method called Main which is the entry point to your program and this method is the first one tobe called when the program starts executing. That is why it is declared static in scope. We will discuss method scopes in upcoming modules.The Main() method takes up a parameter , an array of string used to pass information to main() from the command line at run time.Then there’s the console.writeline which merely prints out the hello from visual studio string on to the screen or the console.The readline() method of the console class waits for the user response before the program can actually exit.The black window is the console output generated.You can use this code to be compiled and executed by the c# compiler either from the command line or from Visual Studio 2010.Upon compilation, .net creates an executable for this console application, which is the binary that is read and executed by the CLR.If you actually open the solution folder of your program ,you will see that an Helloworld.exe is created.
Introduction to C#
Introduction to .NETGoalThe purpose of this module is to introduce Microsoft .NET Framework which is apopular application development platform among programmers. This module willalso introduce the C# programming language to the developer.
What is common amongst all these ? • SQL Server, • Oracle • SAP DB Rich Client Apps Data Driven Apps Web Services Desktop Applications These are all Applications built on top of the .NET FrameworkWeb Applications Windows Mobile Apps Client Server Applications
Outline Lots of Demos Common Type System Framework Class Library Common Language Runtime C# Language Syntax and Usage Visual Studio IDE
Introduction to .NET Your Windows OR Web ApplicationCommon FrameworkLanguage Runtime + Class Library (FCL) = (CLR)
Common Language Runtime(CLR)• Is the heart of .Net Framework• Provides compilation and execution of your .net code• Manages your application when it runs and provides • Memory management & Garbage Collection • Security • Exception Handling • Operating system and hardware independence • Language independence Web Application CLR
Framework Class Library (FCL)• This is the foundation on which the .NET Framework applications , components and controls are built.• Consists of Namespaces that are groups of classes of related functionality.• A comprehensive collection of pre-written object-oriented classes that you can use for: • Data driven Applications • Using XML and interacting with File system etc.
How does a .Net Application compile and Exceute? CLR/CTS CLS VB.NET C#.NET
What is C# ?• Is a popular programming language used to write different types of applications using the .NET Framework• C# has its roots based in C and C++• C# Type-safe, event-driven, component- oriented• Is a completely object-oriented programming language
What is C#?(Continued)• C# syntax is similar to Java• A standardized language (registered with ECMA) to create .NET components – Standardized by ECMA – Create applications, services, and reusable libraries – Syntax is similar to Java and C++