CIT304 Chapter 2 Y24

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Programming with C Sharp (CIT 304)

Introduction to C#

Adedoyin I. OYEBADE
sacnet2015@gmail.com

Bowen University,
Iwo, Nigeria

April 3, 2023

OYEBADE A. (BU) CIT 304 April 3, 2023 1 / 18


Presentation Overview

1 .Net Framework
Introduction .Net Framework
.Net Framework Components
.Net Framework Components
.NET Framework Class Library Namespaces
C# Programming
C# Features
C# Program Sample
C# Using System

OYEBADE A. (BU) CIT 304 April 3, 2023 2 / 18


Definition: .Net Framework

1 .NET is a framework to develop software applications.

2 Uses of .Net Framework


• It is used to develop applications for web, Windows, phone.
Moreover, it provides a broad range of functionalities and
support.

3 This framework provides various services like memory


management, networking, security, memory management,
and type-safety.

4 The .Net Framework supports more than 60 programming


languages

OYEBADE A. (BU) CIT 304 April 3, 2023 3 / 18


.Net Framework Components
1 The Components are:
• Common Language Runtime (CLR):
1 It is a program execution engine that loads and executes the
program
2 It converts the program into native code.

3 It acts as an interface between the framework and operating


system.
4 is a runtime environment that manages and executes the code
written in any .NET programming language.
5 It compiles the source code of applications developed using .NET
compliant languages into CLR’s intermediate language called
MSIL(Microsoft Intermediate Language),

• CLR Components are


1 Common type system
2 Common language speciation
3 Garbage Collector
4 Just in Time Compiler
5 Metadata and Assemblies
OYEBADE A. (BU) CIT 304 April 3, 2023 4 / 18
.Net Framework Components

1 The Components are:


• Framework Class Library (FCL)
1 is a collection of thousands of classes, namespaces, interfaces and
value types that are used for .NET applications
• Framework Class Library (FCL) support the following functions
1 Base and user-defined data types
2 Support for exceptions handling
3 input/output and stream operations
4 Communications with the underlying system
5 Access to data
6 Ability to create Windows-based GUI applications
7 Ability to create web-client and server applications
8 Support for creating web services

OYEBADE A. (BU) CIT 304 April 3, 2023 5 / 18


.Net Framework Components

1 The Components are:


• Core Languages (WinForms, ASP.NET, and ADO.NET)

1 WinForms: Windows Forms is a smart client technology for the


.NET Framework, a set of managed libraries that simplify common
application tasks such as reading and writing to the file system.

2 ASP.NET: is a web framework designed and developed by


Microsoft. It is used to develop websites, web applications, and
web services.

3 ADO.NET: is a module of .Net Framework, which is used to


establish a connection between application and data sources.
Data sources can be such as SQL Server and XML. ADO .NET
consists of classes that can be used to connect, retrieve, insert,
and delete data.
• Other Modules (WCF, WPF, WF, Card Space, LINQ, Entity
Framework, Parallel LINQ, Task Parallel Library, etc.)

OYEBADE A. (BU) CIT 304 April 3, 2023 6 / 18


.NET Framework Class Library Namespaces

1 the commonly used namespaces that contains useful classes


and interfaces and defined in Framework Class Library.
2 System
• It includes all common datatypes, string values, arrays and
methods for data conversion

3 System.Data, System.Data.Common, System.Data.OleDb,


System.Data.SqlClient, System.Data.SqlTypes:
• These are used to access a database, perform commands on a
database and retrieve database

4 System.IO, System.DirectoryServices,
System.IO.IsolatedStorage:
• These are used to access, read and write files

OYEBADE A. (BU) CIT 304 April 3, 2023 7 / 18


.NET Framework Class Library Namespaces

1 System.Diagnostics
• It is used to debug and trace the execution of an application.

2 System.Windows.Forms,System.Windows.Forms.Design
• These namespaces are used to create Windows-based
applications using Windows user interface components.

OYEBADE A. (BU) CIT 304 April 3, 2023 8 / 18


C# Programming

1 It is an object-oriented programming language provided by


Microsoft that runs on .Net Framework

2 With C#, we can develop different types of secured and robust


applications
• Window applications
• Web Applications
• Distributed applications
• Web service applications
• Database applications

OYEBADE A. (BU) CIT 304 April 3, 2023 9 / 18


C# Features

1 The features are

2 Simple:
• C# is a simple language in the sense that it provides structured
approach (to break the problem into parts), rich set of library
functions, data types etc.

3 Modern programming language:


• C# programming is based upon the current trend and it is very
powerful and simple for building scalable, interoperable and
robust applications

4 Object oriented:
• C# is object oriented programming language. OOPs makes
development and maintenance easier where as in
Procedure-oriented programming language it is not easy to
manage if code grows as project size grow.

OYEBADE A. (BU) CIT 304 April 3, 2023 10 / 18


C# Features Cont...

1 The features are

2 Type safe:
• C# type safe code can only access the memory location that it
has permission to execute. Therefore it improves a security of
the program.

3 Interoperability:
• Interoperability process enables the C# programs to do almost
anything that a native C++ application can do

4 Scalable and Updateable:


• C# is automatic scalable and updateable programming
language. For updating our application we delete the old files
and update them with new ones

OYEBADE A. (BU) CIT 304 April 3, 2023 11 / 18


C# Features Cont...

1 The features are

2 Component oriented:
• C# is component oriented programming language. It is the
predominant software development methodology used to
develop more robust and highly scalable applications.

3 Structured programming language:


• is a structured programming language in the sense that we can
break the program into parts using functions. So, it is easy to
understand and modify

4 Rich Library:
• C# provides a lot of inbuilt functions that makes the
development fast. Fast speed: The compilation and execution
time of C# language is fast

OYEBADE A. (BU) CIT 304 April 3, 2023 12 / 18


C# Program Sample

class Program {
static void Main(string[] args) {
System.Console.WriteLine(”Hello World”)
}
}

OYEBADE A. (BU) CIT 304 April 3, 2023 13 / 18


Sample Program Explain

1 Class
• is a keyword which is used to define class

2 Program
• is the class name.
• A class is a blueprint or template from which objects are created.
• It can have data members and methods. Here, it has only Main
method.

3 static
• is a keyword which means object is not required to access static
members. So it saves memory

4 void
• is the return type of the method. It does’t return any value. In
such case, return statement is not required.

OYEBADE A. (BU) CIT 304 April 3, 2023 14 / 18


Sample Program Explain

1 Main
• is the method name. It is the entry point for any C# program.
Whenever we run the C# program, Main() method is invoked
first before any other method. It represents start up of the
program.

2 string[] args
• is used for command line arguments in C#. While running the
C# program, we can pass values. These values are known as
arguments which we can use in the program.

3 System.Console.WriteLine(”Hello World!”):
• System is the namespace. Console is the class defined in System
namespace. The WriteLine() is the static method of Console
class which is used to write the text on the console.

OYEBADE A. (BU) CIT 304 April 3, 2023 15 / 18


C# Using System, public modifier, namespace

1 using System
• it means we don’t need to specify System namespace for
accessing any class of this namespace.
• we are using Console class without specifying System.Console.
using System;
class Program {
static void Main(string[] args) {
Console.WriteLine(”Hello World”);
}
}

OYEBADE A. (BU) CIT 304 April 3, 2023 16 / 18


C# Using System, public modifier, namespace

1 using public modifier


• We can also specify public modifier before class and Main()
method.
• it can be accessed from outside the class also
using System; public class Program {
public static void Main(string[] args) {
Console.WriteLine(”Hello World”);
}
}

OYEBADE A. (BU) CIT 304 April 3, 2023 17 / 18


C# Using System, public modifier, namespace

1 using namespace
• We can create classes inside the namespace.
• It is used to group related classes. It is used to categorize
classes so that it can be easy to maintain.
using System; namespace ConsoleApplication1; { public class
Program {
public static void Main(string[] args) {
Console.WriteLine(”Hello World”);
}
}}

OYEBADE A. (BU) CIT 304 April 3, 2023 18 / 18

You might also like