Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C# Programming Fundamentals: A Comprehensive Guide - Prof. Shinde, Assignments of Computer Science

A comprehensive guide to c# programming fundamentals, covering essential concepts such as data types, control flow, arrays, classes, objects, inheritance, interfaces, file operations, and database connectivity. It includes detailed explanations, code examples, and practical illustrations to enhance understanding and facilitate learning.

Typology: Assignments

2023/2024

Uploaded on 10/06/2024

shivaay-antil
shivaay-antil 🇮🇳

1 document

1 / 153

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download C# Programming Fundamentals: A Comprehensive Guide - Prof. Shinde and more Assignments Computer Science in PDF only on Docsity!

Table of Contents

Chapter 1: What is .NET Framework Chapter 2:

Download and Install Visual Studio Chapter 3:

Data Types Chapter 4: Class and Object Chapter

5: Collections Chapter 6: Windows Forms

Application Chapter 7: Database Access Chapter

8: File Operations

Chapter 1: What is .NET

Framework

The .Net framework is a software development platform developed by Microsoft. The framework was meant to create applications, which would run on the Windows Platform. The first version of the .Net framework was released in the year 2000.

The version was called .Net framework 1.0. The .Net framework has come a long way since then, and the current version is 4.6.1.

The .Net framework can be used to create both - Form based and Web based applications. Web services can also be developed using the .Net framework.

The framework also supports various programming languages such as Visual Basic and C#. So developers can choose and select the language to develop the required application. In this chapter, you will learn some basics of the .Net framework.

.Net Framework Architecture

The basic architecture of the .Net framework is as shown below.

The architecture of the .Net framework is based on the following key components; 1. Common Language Runtime - The “Common Language Infrastructure” or CLI is a platform on which the .Net programs are executed. The CLI has the following key features:

Exception Handling - Exceptions are errors which occur when the application is executed. Examples of exceptions are:

If an application tries to open a file on the local machine, but the file is not present. If the application tries to fetch some records from a database, but the connection to the database is not valid.

Garbage Collection - Garbage collection is the process of removing unwanted resources when they are no longer required. Examples of garbage collection are

A File handle which is no longer required. If the application has finished all operations on a file, then the file handle may no longer be required. The database connection is no longer required. If the

  1. Class Library - The .NET Framework includes a set of standard class libraries. A class library is a collection of methods and functions that can be used for the core purpose. For example, there is a class library with methods to handle all file level operations. So there is a method which can be used to read the text from a file. Similarly, there is a method to write text to a file. Most of the methods are split into either the System.* or Microsoft.* namespaces. (The asterisk * just means a reference to all of the methods that fall under the System or Microsoft namespace) A namespace is a logical separation of methods. We will learn these namespaces more in detail in the subsequent chapters.
  2. Languages - The types of applications that can be built in the .Net framework are classified broadly into the following categories.

WinForms – This is used for developing Forms-based applications, which would run on an end user machine. Notepad is an example of a client-based application. ASP.Net – This is used for developing web based applications, which are made to run on any browser such as Internet Explorer, Chrome or Firefox.

The Web application would be processed on a server, which would have Internet Information Services Installed. Internet Information Services or IIS is a Microsoft component which is used to execute an ASP.net application. The result of the execution is then sent to the client machines, and the output is shown in the browser.

ADO.Net – This technology is used to develop applications to interact with Databases such as Oracle or Microsoft SQL Server.

Different versions of the .Net

framework

Below is the table of .Net framework versions, which have been released with their release dates. Every version has relevant changes to the framework.

For example, in framework 3.5 and onwards a key framework called the Entity framework was released. This framework is used to change the approach in which the applications are developed while working with databases.

Version number CLR version Release date 1.0 1.0 2002-02- 1.1 1.1 2003-04- 2.0 2.0 2005-11- 3.0 2.0 2006-11- 3.5 2.0 2007-11- 4.0 4 2010-04- 4.5 4 2012-08- 4.5.1 4 2013-10- 4.5.2 4 2014-05- 4.6 4 2015-07- 4.6.1 4 2015-11-

The biggest advantage of the .Net framework is that it supports Windows platform. Almost everyone works with Windows machines. Microsoft always ensures that .Net frameworks are in compliance with all the supported Windows operating systems. The following design principles of the .Net framework is what makes it very relevant to create .Net based applications.

  1. Interoperability - The .Net framework provides a lot of backward support. Suppose if you had an application built on an older version of the .Net framework, say 2.0. And if you tried to run the same application on a machine which had the higher version of the .Net framework, say 3.5. The application would still work. This is because with every release, Microsoft ensures that older framework versions gel well with the latest version.

Chapter 2: Download and Install

Visual Studio

Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs for Microsoft Windows. Visual Studio is one stop shop for all applications built on the .Net platform. One can develop, debug and run applications using Visual Studio.

Both Forms based and web based applications can be designed and developed using this IDE. The Visual Studio has the below- mentioned features

  1. Creation of an application in any .Net language – The Visual Studio IDE can be used to create an application in any .Net language. Hence, a developer can use C#, VB.Net or even F# to develop an application.
  2. Creation of any application type – The Visual Studio IDE can be used to create an application of any type. (Web-based application or Windows Forms based application).
  3. Debug Applications on the fly – Applications can be tested as they are being built. The IDE allows one to run the program at any point of time during the development process. Hence, a developer can check for any errors during the development phase itself.
  4. Extensions – The IDE has the facility to install third-party extensions. An example can be Subversion, which is used for source code repository management. Subversion is used to upload code to a central repository. This is done so that a copy of the code will always exist. Visual Studio has the facility to integrate with such software from the IDE itself. Hence, a developer can work with code repositories from the IDE itself.

Let’s look at the installation of this IDE, so that we can work with creating programs in the subsequent chapters. Visual Studio can be downloaded from the following link - https://www.visualstudio.com/en us/downloads/download-visual-studio-vs.aspx

Once you have the Visual Studio Installer, you can install it using the below mentioned steps Step 1) The first steps involves choosing the location for the installation. In this step one also has to accept the License Terms and conditions.

Microsoft Foundation Classes for C++ Microsoft SQL Server Data Tools Microsoft Web Developer Tools

  1. After that, click on the Install button to start the installation. Once the installation is complete, you will get the below screen showing the success of the installation

Chapter 3: Data Types

C# is one of the languages provided by Microsoft to work with .Net. This language encompasses a rich set of features, which allows developing different types of applications.

C# is an object-oriented programming language and resembles several aspects of the C++ Language. In this tutorial, we see how to develop our first application. This will be a basic console application, we will then explore different data types available in the C# language as well as the control flow statements.

Building the first console application

A console application is an application that can be run in the command prompt in Windows. For any beginner on .Net, building a console application is ideally the first step to begin with.

In our example, we are going to use Visual Studio to create a console type project. Next, we are going to use the console application to display a message “Welcome to .Net”. We will then see how to build and run the console application.

Let’s follow the below-mentioned steps to get this example in place.

Step 1) The first step involves the creation of a new project in Visual Studio. For that, once the Visual Studio is launched, you need to choose the menu option New->Project.

  1. In the project dialog box, we can see various options for creating different types of projects in Visual Studio. Click the Windows option on the left-hand side.
  2. When we click the Windows options in the previous step, we will be able to see an option for Console Application. Click this option.
  3. We then give a name for the application which in our case is DemoApplication. We also need to provide a location to store our application.
  4. Finally, we click the ‘OK’ button to let Visual Studio to create our project.

If the above steps are followed, you will get the below output in Visual Studio. Output:

  1. A project called ‘DemoApplication‘ will be created in Visual Studio. This project will contain all the necessary artifacts required to run the Console application.
  2. The Main program called Program.cs is default code file which is created when a new application is created in Visual Studio. This code will contain the necessary code for our console application.

Step 3) Now let’s write our code which will be used to display the string “Welcome to .Net” in the console application. All the below code needs to be entered in the Program.cs file. The code will be used to write “Welcome to .Net” when the console application runs.

Code Explanation:

  1. The first lines of code are default lines entered by Visual Studio. The ‘using’ statement is used to import existing .Net modules in our console application. These modules are required for any .Net application to run properly. They contain the bare minimum code to make a code work on a Windows machine.
  2. Every application belongs to a class. C# is an object-oriented language, and hence, all code needs to be defined in a self- sustaining module called a ‘Class.’ In turn, every class belongs to a namespace. A namespace is just a logically grouping of classes.
  3. The Main function is a special function which is automatically called when a console application runs. Here you need to ensure to enter the code required to display the required string in the console application.
  4. The Console class is available in .Net which allows one to work with console applications. Here we are using an inbuilt method called ‘Write’ to write the string “Welcome to .Net” in the console.
  5. We then use the Console.ReadKey() method to read any key from the console. By entering this line of code, the program will wait and not exit immediately. The program will wait for the user to enter any key before finally exiting. If you don’t include this statement in code, the program will exit as soon as it is run.
  1. Integer – An Integer data types is used to work with numbers. In this case, the numbers are whole numbers like 10, 20 or 30. In C#, the datatype is denoted by the Int32 keyword. Below is an example of how this datatype can be used. In our example, we will define an Int32 variable called num. We will then assign an Integer value to the variable and then display it accordingly.

Code Explanation:

  1. The Int32 data type is specified to declare an Integer variable called num. The variable is then assigned a value of 30.
  2. Finally the console.write function is used to display the number to the console.

If the above code is entered properly and the program is executed successfully, following output will be displayed. From the output, you can clearly see that the Integer variable called num was displayed in the console

  1. Double - A double data type is used to work with decimals. In this case, the numbers are whole numbers like 10.11, 20.22 or 30.33. In C#, the datatype is denoted by the keyword “ Double “. Below is an example of this datatype.

In our example, we will define a double variable called num. We will then assign a Double value to the variable and then display it accordingly.

Code Explanation:

  1. The double data type is specified to declare a double type variable called num.

The variable is then assigned a value of 30.33.

  1. Finally the console.write function is used to display the number to the console. If the above code is entered properly and the program is executed successfully, following output will be displayed. From the output, you can clearly see that the double variable called num was displayed in the console
  2. Boolean - A boolean data type is used to work with Boolean values of true and false. In C#, the datatype is denoted by the Boolean keyword. Below is an example of this datatype can be used.

In our example, we will define a Boolean variable called ‘status.’ We will then assign a boolean value to the variable and then display it accordingly.

Code Explanation:

  1. The boolean data type is specified to declare a Boolean variable called ‘status.’