19
C# LANGUAGE BY BOWYA G

BY BOWYA G. This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

Embed Size (px)

Citation preview

Page 1: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

C# LANGUAGE

BY

BOWYA G

Page 2: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

HISTORY

This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#.

It was developed within Microsoft.

The first widely distributed implementation of C# was released by Microsoft in July 2000, as part of its .NET Framework initiative.

Its runs with Common Language Infrastructure

Page 3: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

GOALS The language is intended for use in developing

software components suitable for deployment in distributed environments.

C# is intended to be a simple, modern, general-purpose, object-oriented programming language.

Support for internationalization is very important.

This programmers already familiar with C and C++.

Page 4: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

C# is intended to be suitable for writing applications for both hosted and embedded systems.

Although C# applications are intended to be economical with regards to memory and processing power requirements, the language was not intended to compete directly on performance and size with C or assembly language.

The development of this standard started in November 2000.

Page 5: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

DATA TYPES

C# supports two kinds of types: value types and reference types.

Value types include simple types (e.g.,char, int, and float), enum types, and struct types.

Reference types include class types, interface types,delegate types, and array types.

Page 6: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

Value types differ from reference types in that variables of the value types directly contain their data, whereas variables of the reference types store references to objects.

The reference types, it is possible fortwo variables to reference the same object, and thus possible for operations on one variable to affect the object referenced by the other variable. With

Page 7: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

EXAMPLEusing System;

class Class1

{

public int Value = 0;

}

class Test

{

static void Main()

{

int val1 = 0;

int val2 = val1;

val2 = 123;

Class1 ref1 = new Class1();

Page 8: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

Class1 ref2 = ref1;

ref2.Value = 123;

Console.WriteLine("Values: {0}, {1}", val1, val2);

Console.WriteLine("Refs: {0}, {1}", ref1.Value, ref2.Value);

}

}

Output: Values: 0, 123 Refs: 123, 123

Page 9: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

PREDEFINED TYPES

Type Description Example

string String type string s = "hello";

sbyte 8-bit signed type sbyte val = 12;

short 16-bit signed type short val = 12;

byte 8-bit signed type byte val1 = 12;

ushort 16-bit signed type ushort val1 = 12;

int 32-bit signed type int val = 12;

Long 64-bit signed type Long val=122;

float Single-precision floating point type

float val = 1.23F;

double double Double-precision floating point type

double val1 = 1.23;double val2 = 4.56D;

Page 10: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

ARRAYS Arrays may be single-dimensional or multi-

dimensional. Both .rectangular. and .jagged. arrays are supported.

Jagged array is important concept in c#.

creates a single-dimensional array of int values, initializes the array elements, and then prints each of them out.

Ex : int[] arr = new int[5];

Page 11: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

SINGLE ARRAYusing System;class Test{static void Main() {int[] arr = new int[5];for (int i = 0; i < arr.Length; i++)arr[i] = i * i;for (int i = 0; i < arr.Length; i++)Console.WriteLine("arr[{0}] = {1}", i, arr[i]);}}

Page 12: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

Output :

arr[0] = 0

arr[1] = 1

arr[2] = 4

arr[3] = 9

arr[4] = 16

here int[] used in the previous example is an array type.

Page 13: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

CLASSES Class members can include constants,

fields, methods, properties, events, indexers, operators, instance constructors, destructors, static constructors, and nested type declarations.

Class declarations define new reference types. A class can inherit from another class, and can implement interfaces.

Page 14: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

Form Meaning

public Access not limited

protected Access limited to the containing class or types derived from the containing class

internal Access limited to this program

private Access limited to the containing type

Page 15: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

DESTRUCTORS A destructor is a member that implements the

actions required to destruct an instance of a class.

Destructors cannot have parameters, they cannot have accessibility modifiers, and they cannot be called explicitly.

The destructor for an instance is called automatically during garbage collection.

Page 16: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

EXAMPLEusing System;

class Point

{

public double x, y;

public Point(double x, double y) {

this.x = x;

this.y = y;

}

~Point() {

Console.WriteLine("Destructed {0}", this);

}

public override string ToString() {

return string.Format("({0}, {1})", x, y);

}

}

Page 17: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

STATIC CONSTRUCTORS A static constructor is a member that implements

the actions required to initialize a class.

Static constructors cannot have parameters, they cannot have accessibility modifiers, and they cannot be called explicitly

The static constructor for a class is called automatically.

Page 18: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

EXAMPLEusing Personnel.Data;class Employee{private static DataSet ds;static Employee() {ds = new DataSet(.);}public string Name;public decimal Salary;.}

Page 19: BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#

THANK YOU..!