Presentation is loading. Please wait.

Presentation is loading. Please wait.

C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –

Similar presentations


Presentation on theme: "C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –"— Presentation transcript:

1 C# Fundamentals An Introduction

2 Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 – C# 6.0, Visual Studio.NET 2015

3 .NET YOUR APPLICATION Microsoft.NET Common Language Runtime (CLR) Framework Class Library (FCL)

4 Framework Class Library A library of functionality to build applications

5 C# One of the languages for.Net – Create applications, services and reusable libraries – Syntax is very similar to java, C++, Javascript

6 Types Classes – A class may be composed of any number of members (such as constructors, properties, methods, and events) and data points (fields). In C#, classes are declared using the class keyword Enums – Enumerations are a handy programming construct that allow you to group name/value pairs. For example, assume you are creating a video game application that allows the player to select one of three character categories (Wizard, Fighter, or Thief). Rather than keeping track of simple numerical values to represent each possibility, you could build a strongly typed enumeration using the enum keyword.

7 Structs – a structure can be thought of as a lightweight class type having value-based semantics. Typically, structures are best suited for modeling geometric and mathematical data and are created in C# using the struct keyword. Interface – Interfaces are nothing more than a named collection of abstract member definitions, which may be supported (i.e., implemented) by a given class or structure. In C#, interface types are defined using the interface keyword. Delegates

8 Statements The actions that a program takes are expressed in statements. Common actions include declaring variables, assigning values, calling methods, looping through collections, and branching to one or another block of code, depending on a given condition.

9 Types of statements in C# Declaration statements – A declaration statement introduces a new variable. Expression statements – Expression statements that calculate a value must store the value in a variable. – // Expression statement (new object creation). System.Collections.Generic.List strings = new System.Collections.Generic.List (); Selection statements – Selection statements enable you to branch to different sections of code, depending on one or more specified conditions. (if, else, switch, case)ifelseswitchcase Iteration statements – Iteration statements enable you to loop through collections like arrays, or perform the same set of statements repeatedly until a specified condition is met. (do, for, foreach, in, while)doforforeachinwhile Exception handling statements – Exception handling statements enable you to gracefully recover from exceptional conditions that occur at run time. (throw, try-catch, try-finally, try- catch-finally)throwtry-catchtry-finallytry- catch-finally

10 OOPS Inheritance Abstraction Encapsulation Polymorphism

11 Encapsulation According to the principle of encapsulation, a class or struct can specify how accessible each of its members is to code outside of the class or struct. Methods and variables that are not intended to be used from outside of the class or assembly can be hidden to limit the potential for coding errors or malicious exploits.

12 Members All methods, fields, constants, properties, and events must be declared within a type; these are called the members of the type The following list includes all the various kinds of members that may be declared in a class or struct. Fields Constants Properties Methods Constructors Events Indexers Nested Types

13 Access Modifiers Access modifiers are keywords used to specify the declared accessibility of a member or a type. public : Access is not restricted. protected : Access is limited to the containing class or types derived from the containing class. Internal : Access is limited to the current assembly. protected internal: Access is limited to the current assembly or types derived from the containing class. protected internal private : Access is limited to the containing type.

14 Polymorphism At run time, objects of a derived class may be treated as objects of a base class in places such as method parameters and collections or arrays. When this occurs, the object's declared type is no longer identical to its run-time type. Base classes may define and implement virtual methods, and derived classes can override them, which means they provide their own definition and implementation.virtualoverride

15 Types of Polymorphism Compile Time Polymorphism – We declare methods with same name but different signatures because of this we will perform different tasks with same method name. Run Time Polymorphism – Example

16 Delegates A Type Safe Function Pointer A delegate is a references type that invokes single/multiple method(s) through the delegate instance. It holds a reference of the methods. A Delegate is similar to class. You can create an instance of it, and pass in the function name as a parameter it points to.

17 Types Of Delegates Single Delegate Multicast Delegate Generic Delegate – Action – Predicate – Func

18 Anonymous methods Anonymous method is a method without a name. They provide us a way of creating delegate instances without having to write a separate method.


Download ppt "C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –"

Similar presentations


Ads by Google