introduction to c #

19
www.sirymedi a.in Introduction to C# (CSharp).net Brought to you by www.SiryMedia.in

Transcript of introduction to c #

Page 1: introduction to c #

www.sirymedia.inIntroduction to C# (CSharp).net

Brought to you by www.SiryMedia.in

Page 2: introduction to c #

www.sirymedia.in• C# developed by Microsoft and comes after C, C++, Java. It inherits

the properties of C, C++, Java, VB. • We can say C# is smart and intelligent sister of Java because it do

work smartly in compression to Java. • The basic concept of C# language are same as C, C++ to whom you

have learnt in C, C++ tutorials. • Launched in visual studio 2008• Create a console with visual c# language• It generates empty program class with main() method

Page 3: introduction to c #

www.sirymedia.in• File extension in c# • Project file extension: “.csproj” (Means c sharp project)• Sample application development in C#• Create a new “console application ” with “visual C#” language• It generates an empty “program” class with “main()” method• To run an application simply press f5 key on the keyboard. Then

the application will be executed and output will be displayed

Page 4: introduction to c #

www.sirymedia.in

Importing section• This section contain importing statements that are used to import

(including or link) the .NET framework class library FCL.• This is most similar to the include statement in c language• Syntax: using namespace• Note: if requires namespace is a member of another name space. We

have specify the parent and child namespaces separate with “.” (dot).• Ex: using system;• Using system.io;• Using system.data;

Page 5: introduction to c #

www.sirymedia.in

Namespace declaration:

• Here a user define namespace is to be declared• Rule : In .NET applications, all the classes related to the

project should be declared in one namespace.• Syntax: namespace namespacename{}• Generally, the namespace name will be same as “project ”

name.

Page 6: introduction to c #

www.sirymedia.in

Class declaration

• This is to declare the startup class of the project.• In every .NET application like console and windows

application. There should be a startup class name should be “program” you cant change it

• A startup class is nothing a class, which contain main() method.

• Syntax: class classname{}

Page 7: introduction to c #

www.sirymedia.in

Class

• Class is a data structure that contains data members (constants files, events), member function methods, properties, constructor, destructor, indexers and nested type. Basically :

• It is a user defined data type.• It is a reference type.• In fact class is a tag or template for object.

• Drawback of Class• Class does not allocate memory to its data members & member function itself.

Basically memory is allocated through object of a class. Class can’t explore itself means it can not access its members itself, to access members of a class we use object of that class.

Page 8: introduction to c #

www.sirymedia.in

Object

• Object is representative of the class and is responsible for memory allocation of its data members and member functions.

• An object is a real world entity having attributes (data type) and behaviors (functions).

Page 9: introduction to c #

www.sirymedia.in

Main() method• As you know already in c/c++ languages. The main()

method is the starting execution point of the application• When the application is executed the main method will be

executed first• This method contains the main logic of the application

Page 10: introduction to c #

www.sirymedia.in

• Class program• {• static void• Main(string[] args)• {• Console.writeline (“hello world!”);• Console.readline();• } • }• Compiling and running application:• Compile: click on “build” menu – “build solution”.(or) press ctrl + shift + B• Run:• Click on “debug” menu – “start debugging” . (Or) press f5.

Page 11: introduction to c #

www.sirymedia.inC#.net supports no of applications:• 1.Console applications• 2.OOPS• 3.Class libraries• 4.Window forms applications• 5.Windows forms control library• 6.Windows services• 7.ado.net

Page 12: introduction to c #

www.sirymedia.in• 8.mdi forms• 9.gdi • 10.multi threading• 11.exception handling• 12.linq• 13.security• 14.remoting• 15.globalization &localization• 16.crystal reports• 17.setup & deployments

Page 13: introduction to c #

www.sirymedia.inex:• using System;• namespace ConsoleApplication1• { class emp //class• { int sal, bonus, ta, ts; //properties• public void tsal() //method• { sal = 10000;• bonus = 5000;• ta = 500;• ts = sal + bonus + ta;• Console.WriteLine("the total salary is:" + ts.ToString());• Console.ReadLine();• }

Page 14: introduction to c #

www.sirymedia.in• static void Main(string[] args)• { emp obj = new emp(); //instance

variable• obj.tsal(); //calling the

method• } • } • }

Page 15: introduction to c #

www.sirymedia.in• // Namespace Declaration• using System; • // helper class • class ClassA • { • string myString; • // Constructor• public ClassA(string str) • { • myString = str;• } • // Instance Method • public void Show() • { • Console.WriteLine("{0}", myString);• }

Page 16: introduction to c #

www.sirymedia.in• // Destructor • ~ClassA()• { • // Some resource cleanup routines• } • } • // Program start class • class ClassProgram • { • // Main begins program execution• public static void Main() • { • // Instance of ClassA • ClassA objA = new ClassA("Welcome to the world of C# language !!");• // Call ClassA method • objA.Show();• } • }

Page 17: introduction to c #

www.sirymedia.in

Platform Support• I've put this last only because it doesn't appear to differentiate

these languages as much as you might think. All these languages can run on multiple OS es and machine architectures. C is the most widely-supported, then C++, and finally C# (although C# can be used on most major platforms thanks to an open source implementation called Mono).

• My experience of porting C++ programs between Windows and various Unix flavors was unpleasant. I've never tried porting anything very complex in C# to Mono, so I can't comment on that.

Page 18: introduction to c #

www.sirymedia.inFor more understanding visit our c# program example playlist in our channel SIRYMEDIA

Or Click below links in description

Page 19: introduction to c #

www.sirymedia.in

Thank You For more updates subscribe to our YouTube channel

SiryMedia To watch more videos visit our website www.sirymedia.in