www.sirymedia.inIntroduction to C# (CSharp).net
Brought to you by www.SiryMedia.in
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
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
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;
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.
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{}
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.
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).
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
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.
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
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
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();• }
www.sirymedia.in• static void Main(string[] args)• { emp obj = new emp(); //instance
variable• obj.tsal(); //calling the
method• } • } • }
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);• }
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();• } • }
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.
www.sirymedia.inFor more understanding visit our c# program example playlist in our channel SIRYMEDIA
Or Click below links in description
www.sirymedia.in
Thank You For more updates subscribe to our YouTube channel
SiryMedia To watch more videos visit our website www.sirymedia.in