0% found this document useful (0 votes)
8 views

C# Introduction

For students in computerscience
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

C# Introduction

For students in computerscience
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

C# INTRODUCTION

INTRODUCTION TO .NET
FRAMEWORK
The Big Ideas

A Brief Description of the .NET framework and its components.

Overview of C#

First C# Program “Hello UZ Programmers”

Program structure

Basic Syntax

Overview of the environment - Visual Studio IDE


C# – The Big Ideas
• The first component oriented language in the
C/C++ family
• Everything really is an object
• Next generation robust and durable software
• Preservation of investment
C# – The Big Ideas
A component oriented language

• C# is the first “component oriented” language in the


C/C++ family
• Component concepts are first class:
• Properties, methods, events
• Design-time and run-time attributes
• Integrated documentation using XML
• Enables one-stop programming
• No header files, IDL, etc.
• Can be embedded in web pages
C# – The Big Ideas
Everything really is an object

• Traditional views
• C++, Java: Primitive types are “magic” and do not
interoperate with objects
• Smalltalk, Lisp: Primitive types are objects, but at great
performance cost
• C# unifies with no performance cost
• Deep simplicity throughout system
• Improved extensibility and reusability
• New primitive types: Decimal, SQL…
• Collections, etc., work for all types
C# – The Big Ideas
Robust and durable software

• Garbage collection
• No memory leaks and stray pointers
• Exceptions
• Error handling is not an afterthought
• Type-safety
• No uninitialized variables, unsafe casts
• Versioning
• Pervasive versioning considerations in all aspects of language
design
C# – The Big Ideas
Preservation of Investment
• C++ heritage
• Namespaces, enums, unsigned types, pointers (in unsafe
code), etc.
• No unnecessary sacrifices
• Interoperability
• What software is increasingly about
• MS C# implementation talks to XML, SOAP, COM, DLLs,
and any .NET language
• Millions of lines of C# code in .NET
• Short learning curve
• Increased productivity
.NET Framework

• .NET Framework:- platform that provides required tools, technologies and


structure to develop Windows, Web and Enterprise applications.

• It is a software development framework.

• It provides the library and runtime environment

• It mainly contains two components:-


1. Common Language Runtime (CLR)

2. .NET Framework Class Library. (FCL)


Components
Common Language Runtime (CLR)
• .NET Framework provides runtime environment called Common Language
Runtime (CLR).

• Provides an environment to run all the .NET Programs.

• provides memory management and thread management.

• Language Compilers (e.g. C#, VB.NET, J#) will convert the Code/Program to Microsoft
Intermediate Language (MSIL) intern this will be converted to Native Code by CLR.
.NET Framework Class Library (FCL)
• The Framework Class Library is a huge library of reusable types meant to be used
by the managed codes.

• Made up of a hierarchy of namespaces that expose classes, structures, interfaces


and delegates.

• .NET Framework consists of classes, interfaces and value types that help in
speeding up the development process and provide access to system functionality.
C#.NET
• Object oriented programing language
• C# enables development of applications that runs on the .NET Framework.
• Developed by Microsoft
• C# 8
• C# can be used to create:-
1. Windows client applications,
2. XML Web services,
3. distributed components,
4. client-server applications,
5. database applications etc.
C# - Program Structure
A C# program consists of the following parts −
• Namespace declaration
• Specified by the Using Directive
• A class
• Class methods
• Class attributes
• A Main method
• Statements and Expressions
• Comments
• Inline/Single line comments - indicated by two forward slashes //
• Multiline/Block comments – marked by /*…….*/
Program Structure
Namespaces
• Namespaces provide a way to uniquely identify a type
• Provides logical organization of types
• Namespaces can span assemblies
• Can nest namespaces
• There is no relationship between namespaces and file structure
(unlike Java)
• The fully qualified name of a type includes all namespaces
Program Structure
Namespaces

namespace N1 { // N1
class C1 { // N1.C1
class C2 { // N1.C1.C2
}
}
namespace N2 { // N1.N2
class C2 { // N1.N2.C2
}
}
}
Program Structure
Namespaces
• The using statement lets you use types without typing the fully
qualified name
• Can always use a fully qualified name

using N1;

C1 a; // The N1. is implicit


N1.C1 b; // Fully qualified name

C2 c; // Error! C2 is undefined
N1.N2.C2 d; // One of the C2 classes
C1.C2 e; // The other one
Program Structure
Namespaces
• The using statement also lets you create aliases

using C1 = N1.N2.C1;
using N2 = N1.N2;

C1 a; // Refers to N1.N2.C1
N2.C1 b; // Refers to N1.N2.C1
Program Structure
Namespaces
• Best practice: Put all of your types in a unique namespace
• Have a namespace for your company, project, product, etc.
• Look at how the .NET Framework classes are organized
Program Structure
References
• In Visual Studio you specify references for a project
• Each reference identifies a specific assembly
• Passed as reference (/r or /reference) to the C# compiler

csc HelloWorld.cs /reference:System.WinForms.dll


Program Structure
Namespaces vs. References
• Namespaces provide language-level naming shortcuts
• Don’t have to type a long fully qualified name over and over
• References specify which assembly to use
Program Structure
Main Method
• Execution begins at the static Main() method
• Can have only one method with one of the following signatures in an
assembly
• static void Main()
• static int Main()
• static void Main(string[] args)
• static int Main(string[] args)
Program Structure
Syntax
• Identifiers
• Names for types, methods, fields, etc.
• Must be whole word – no white space
• Unicode characters
• Begins with letter or underscore
• Case sensitive
• Must not clash with keyword
• Unless prefixed with @
Example
using System;

namespace HelloWorldApplication {
class HelloWorld {
static void Main(string[] args) {
/* my first program in C# */
Console.WriteLine("Hello HCE&HSE Programmers");
Console.Read();
}
}
Using Visual Studio.NET
• Types of projects
• Console Application
• Windows Application
• Web Application
• Web Service
• Windows Service
• Class Library
• ...
Using Visual Studio.NET
• Windows
• Solution Explorer
• Class View
• Properties
• Output
• Task List
• Object Browser
• Server Explorer
• Toolbox
Using Visual Studio.NET
• Building
• Debugging
• Break points
• References
• Saving
Using .NET Framework SDK
• Compiling from command line

csc /r:System.WinForms.dll class1.cs file1.cs


Overview of the environment

• Visual Studio IDE


• Installation of Visual Studio

You might also like