Saturday, February 27, 2016

C Sharp :Introduction

C# is  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 comprasion to Java. The basic concept of C# language are same as C, C++ to whom you have learnt in C, C++ tutorials. The advance concept of C# language are as :

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).

Class

Class is a data structure that contains data members (constants files, events), member function methods, properties, constructor, destructor, indexers and nested type.Basically :
  1. It is a user defined data type.
  2. It is a reference type.
  3. Infact 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.

Example :

  1. // Namespace Declaration
  2. using System;
  3. // helper class
  4. class ClassA
  5. {
  6. string myString;
  7. // Constructor
  8. public ClassA(string str)
  9. {
  10. myString = str;
  11. }
  12. // Instance Method
  13. public void Show()
  14. {
  15. Console.WriteLine("{0}", myString);
  16. }
  17. // Destructor
  18. ~ClassA()
  19. {
  20. // Some resource cleanup routines
  21. }
  22. }
  23. // Program start class
  24. class ClassProgram
  25. {
  26. // Main begins program execution
  27. public static void Main()
  28. {
  29. // Instance of ClassA
  30. ClassA objA = new ClassA("Welcome to the world of C# language !!");
  31. // Call ClassA method
  32. objA.Show();
  33. }
  34. }

No comments:

Post a Comment