C# Unit 1
C# Unit 1
NET Framework
UNIT-I
INTRODUCTION
• ASP .NET: Web-Based applications come under this category. ASP.Net is a framework for web and it provides
the awesome integration of HTML, CSS and JavaScript which makes it useful to develop the web applications,
websites and web services. Web services were added in .Net Framework 2.0 and considered as a part of ASP.NET
web applications.
• ADO .NET: It includes the application which are developed to communicate with the database like MS SQL
Server, Oracle etc. comes. It mainly consists of classes that can be used to connect, retrieve, insert and delete
data.
4. WPF (Windows Presentation Foundation): Windows Presentation Foundation (WPF) is a graphical
subsystem given by Microsoft which uses DirectX and is used in Windows-based applications for rendering UI
(User Interface). WPF was initially released as part of .NET Framework 3.0 in 2006 and previously known as
“Avalon”.
5. WCF (Windows Communication Foundation): It is a framework for building connected and service-oriented
applications used to transmit the data as asynchronous from one service endpoint to another service point. It was
previously known as the Indigo.
6. WF (Windows Workflow Foundation): It is a technology given by Microsoft which provides a platform for
building workflows within .Net applications.
7. Card Space: It is a Microsoft .NET Framework software client which is designed to let users provide their digital identity to
online services in a secure, simple and trusted way.
8. LINQ (Language Integrated Query): It is introduced in .Net framework version 3.5. Basically, it is a query language used to
make the query for data sources with VB or C# programming languages.
9. Entity Framework: It is open–source ORM (Object Relational Mapping) based framework which comes into .Net Framework
version 3.5. It enables the .Net developer to work with database using .Net objects. Before entity framework, .Net developers have
performed a lot of things related database.
10. Parallel LINQ (Language Integrated Query): It comes in .Net Framework version 4.0 and also termed as PLINQ. It provides
a concurrent query execution engine for LINQ. It executes the LINQ in parallel such that it tries to use as much processing power
system on which it is executing.
11. TPL (Task Parallel Library): It is a set of public types and APIs. It allows the developers to be more productive by simplifying
the process of adding concurrency and parallelism to .Net applications.
12. .NET API For Store/UWP Apps: In 2012, Microsoft added some APIs for creating UWP (Universal Windows Platform) apps
for Windows using C# or VB.
13. Task-Based Asynchronous Model: It is model used to describe the asynchronous operations and tasks in .Net Framework.
1.2 BASIC ELEMENTS OF C#
C# is a programming language of .Net Framework. C# is a programming language
of .Net Framework. By the help of C# programming language, we can develop different
types of secured and robust applications:
• Window applications
• Web applications
• Distributed applications
• Web service applications
• Database applications etc.
• Windows From Application - This is GUI based, runs in a window of some sort
• Console Application - This application runs in the command prompt
Java C#
1) Java is a high level, robust, secured and object- C# is an object-oriented programming language
oriented programming language developed by developed by Microsoft that runs on .Net Framework.
Oracle.
2) Java programming language is designed to be C# programming language is designed to be run on
run on a Java platform, by the help of Java the Common Language Runtime (CLR).
Runtime Environment (JRE).
3) Java type safety is safe. C# type safety is unsafe.
4) In java, built-in data types that are passed by In C#, built-in data types that are passed by value are
value are called primitive types. called simple types.
5) Arrays in Java are direct specialization of Arrays in C# are specialization of System.
Object.
6) Java does not support conditional compilation. C# supports conditional compilation using
preprocessor directives.
7) Java doesn't support goto statement. C# supports goto statement.
8) Java doesn't support structures and unions. C# supports structures and unions.
9) Java supports checked exception and C# supports unchecked exception.
unchecked exception.
C# Features
C# is object oriented programming language. It provides a lot of features that are given below.
• Simple
• Modern programming language
• Object oriented
• Type safe
• Interoperability
• Scalable and Updateable
• Component oriented
• Structured programming language
• Rich Library
• Fast speed
C# Example: Hello World
In C# programming language, a simple "hello world" program can be written by multiple
ways. Let's see the top 4 ways to create a simple C# example:
1. System Example
2. Using System
3. Using public modifier
4. Using namespace
1. C# Example: Simple Example
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("Hello World!");
}
}
Output:
Hello World!
2. C# Example: Using System
If we write using System before the class, it means we don't need to specify System namespace
for accessing any class of this namespace. Here, we are using Console class without specifying
System.Console.
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
Output:
Hello World!
3. C# Example: Using public modifier
We can also specify public modifier before class and Main() method. Now, it can be
accessed from outside the class also.
using System;
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
} }
Output:
Hello World!
4. C# Example: 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!");
}
}}
Output:
Hello World!
C# Variable
A variable is a name of memory location. It is used to store data. Its
value can be changed and it can be reused many times. It is a way to represent
memory location through symbol so that it can be easily identified. The basic
variable type available in C# can be categorized as:
Variable Type Example
Decimal types decimal
Boolean types True or false value, as
assigned
Integral types int, char, byte, short, long
Floating point types float and double
Nullable types Nullable data types
SDK Framework
SDK stands for Software Development
Framework (Software Framework) is
Kit. It includes tools and utilities required
basically a platform which is used for
for the development of the applications. It
developing software applications. It
Definition often includes files to interface to a
provides the necessary foundation on
particular programming language,
which the programs can be developed for a
sophisticated hardware to interact with an
specific platform.
embedded system, debugging tools, etc.
Application
Programming Generally, it includes one or two API Technically, a framework includes an API
Interface
Key Feature Tools for developing applications Platform for developing applications
Android Application Framework for
Example Windows 7 SDK
Android
1.5 UNDERSTANDING THE C# COMPILER
Source code Compilation process
Example:
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
string firstName = "John";
string lastName = "Doe";
string name = $"My full name is: {firstName} {lastName}";
Console.WriteLine(name);
}
}}
1.10 ARRAYS
C# Arrays
Arrays are used to store multiple values in a single variable,
instead of declaring separate variables for each value. To declare an
array, define the variable type with square brackets:
Syntax:
string[] cars;
string[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
int[] myNum = {10, 20, 30, 40};
Access the Elements of an Array
To access an array element by referring to the index number. This statement accesses the value of the
first element in cars. Array indexes start with 0: [0] is the first element. [1] is the second element, etc.
Example:
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
string[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
Console.WriteLine(cars[0]);
} }
}
Output:
Volvo
Sort Arrays foreach (string i in cars)
{
There are many array methods available, for example Console.WriteLine(i);
Sort(), which sorts an array alphabetically or in an }
ascending order.
using System; // Sort an int
int[] myNumbers = {5, 1, 8, 9};
namespace MyApplication Array.Sort(myNumbers);
{ foreach (int i in myNumbers)
{
class Program Console.WriteLine(i);
{ } } }
}
static void Main(string[] args) Output:
{ BMW
// Sort a string Ford
Mazda
string[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; Volvo
Array.Sort(cars); 1
5
8
9
Other Ways to Create an Array