c# Tutorial

Introduction of c# -:C# is an object-oriented language, but C# also  support for component-oriented programming. Contemporary software design increasingly relies on software components in the form of self-contained and self-describing packages of functionality. Key to such components is that they present a programming model with properties, methods, and events.

Programming structure in c# -: Like any other programming language C# has a Programming structure.  C# are programs, namespaces, types, members, and assemblies. C# programs consist of one or more source files. these list..

  • Program declare types-: It contain members and can be organized into namespaces.
  • Classes and interfaces are examples of types.
  • Fields
  •  methods
  • properties
  • events are examples of members.
  • Class methods
  • Class attributes

Data type in c# -: In the C# programming language has two types data types. There are

  • Value types-: Variables of value types directly contain their data, whereas variables of reference types store references to their data, the latter being known as objects
  • Reference types.-: it is possible for two variables to reference the same object and, therefore, possible for operations on one variable to affect the object referenced by the other variable.

In the With value types, the variables each have their own copy of the data, and it is not possible for operations on one to affect the other (except in the case of ref and out parameter variables).

Variable in c# -:  Like any other programming language c#  also support many variable.Variables represent storage locations. Every variable has a type that determines what values can be stored in the variable. C# is a type-safe language, and the C# compiler guarantees that values stored in variables are always of the appropriate type. The value of a variable can be changed through assignment or through use of the ++ and — operators.

Constant in c#-: The constants refer to fixed values.The constant value can not change during the program execution . These fixed values are also called literals. Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal.

A variable in C# can be made into a compile-time constant by adding the const keyword before the data type. This modifier means that the variable cannot be changed and it must therefore be assigned a value at the same time as it is declared. Any attempts to assign a new value to the constant will result in a compile-time error.

Operator in c#-: The operators of an expression indicate which operations to apply to the operands. Examples of operators include +, -, *, /, and new. Examples of operands include literals, fields, local variables, and expressions.

In the c# programming language has three types operators

  1. Unary operators. -:The unary operators take one operand and use either prefix notation (such as –x) or post fix notation (such as x++).
  2. Binary operators.-: The binary operators take two operands and all use infix notation (such as x + y). Such as a Arithmetic operator,logical operator,Relation Operator,Bitwise operator etc.
  3. Ternary operator.-: Only one ternary operator, ?:, exists; it takes three operands and uses infix notation (c? x: y).

Classes in c# -:  A class is a data structure that may contain data members (constants and fields), function members (methods, properties, events, indexers, operators, instance constructors, destructors, and static constructors), and nested types. Class types support inheritance, a mechanism whereby a derived class can extend and specialize a base class.

Abstract class in c#-:This is a type of class in c# language.An abstract class provides a partial implementation that other classes can build on. When a class is declared as abstract, it means that the class can contain incomplete members that must be implemented in derived classes, in addition to normal class members.

Abstract Members-: Any member that requires a body can be declared abstract—such as methods, properties, and indexers. These members are then left unimplemented and only specify their signatures, while their bodies are replaced with semicolons.

Control statement in c#-: C# provides a variety of statements. Most of these statements will be familiar to developers who have programmed in C and C++. C# provide following statement-:

1     labeled-statement
2     declaration-statement
3      embedded-statement

Array in c#-:  An array is a data structure used for storing a collection of values that all have the same data type.An array is a data structure that contains a number of variables that are accessed through computed indices. The variables contained in an array, also called the elements of the array, are all of the same type, and this type is called the element type of the array.

An array has a rank that determines the number of indices associated with each array element. The rank of an array is also referred to as the dimensions of the array. An array with a rank of 1 is called a single-dimensional array. An array with a rank greater than 1 is called a multi-dimensional array. Specific-sized multi-dimensional arrays are often referred to as two-dimensional arrays, three-dimensional arrays, and so on.

Interface in c#-:  An interface defines a contract. A class or struct that implements an interface must adhere to its contract. An interface may inherit from multiple base interfaces, and a class or struct may implement multiple interfaces.

in other words we can say that the An interface is used to specify members that deriving classes must implement. They are defined with the interface keyword followed by a name and a code block. Their naming convention is to start with a capital I and then to have each word initially capitalized

Enum in c#-:: An enumeration is a special kind of value type consisting of a list of named constants. To create one,we can use the enum keyword followed by a name and a code block containing a comma-separated list of constant elements.

Delegate in c# programming-:A delegate is a type used to reference a method. This allows methods to be assigned to variables and passed as arguments. The delegate’s declaration specifies the method signature to which objects of the delegate type can refer. Delegates are by convention named with each word initially capitalized, followed by Delegate at the end of the name.

Inheritance in c#-:Inheritance is a “is a kind of” relationship and the cornerstone of object-oriented programming. For example, a rectangle, an ellipse, and a triangle are “a kind of” shape.

Without inheritance, we should have to fully and independently implement the rectangle, ellipse, and triangle classes. It is better to extrapolate the common elements of any shape and place those elements into a general class.

Structure in c#-: The struct keyword in C# is used to create value types. A struct is similar to a class in that it represents a structure with mainly field and method members. However, a struct is a value type, whereas a class is a reference type. Therefore, a struct variable directly stores the data of the struct, while a class variable only stores a reference to an object allocated in memory.

Exception In c#-: Exception handling helps applications trap and respond in a predictable and robust manner to exceptional events. This enhances the correctness of an application, which naturally improves customer satisfaction.

Exception handling is an important ingredient of a robust application, but it is often an afterthought. We should proactively consider exception handling as an integral part of the application design and include it in all aspects of application planning and development. Conversely, treating exception handling as an afterthought leads to poorly implemented solutions for exception handling and a less robust application.

 Exceptions in C# provide a structured, uniform, and type-safe way of handling both system-level and application-level error conditions.

Exception Handling In c#-:Exception handling allows programmers to deal with unexpected situations that may occur in programs.As an example,consider opening a file using the StreamReader class in the System.IO namespace. To see what kinds of exceptions this class may throw, we can hover the cursor over the class name in Visual Studio. For instance, we may see the System.IO exceptions FileNotFoundException and DirectoryNotFoundException. If any of those exceptions occurs, the program will terminate with an error message

Pointer in C Sharp A pointer is a variable whose value is the address of another variable as like  the direct address of the memory location. similar to any variable or constant, we must declare a pointer before we can use it to store any variable address.

Preprocessor in c#-:Preprocessor directives define symbols, undefined symbols, include source code, exclude source code, name sections of source code, and set warning and error conditions.

Polymorphism in c#-:  Polymorphism is one of the major benefits of inheritance. With polymorphism, the correct function call is decided at run time based on the derived type of a base reference. This is called late binding and is accomplished by casting instances of related types back to a common base class reference. The common base class makes the derived classes related.

Events in c#-:Events enable an object to notify other objects when something of interest occurs. The object that raises the event is called the publisher and the objects that handle the event are called subscribers.

Generic in c#-:Generics refer to the use of type parameters, which provide a way to design code templates that can operate with different data types. Specifically, it is possible to create generic methods, classes, interfaces, delegates, and events.

Namespace in c#-: Namespaces provide a way to group related top-level members into a hierarchy. They are also used to avoid naming conflicts. A top-level member, such as a class, that is not included in a namespace is said to belong to the default namespace. It can be moved to another namespace by being enclosed in a namespace block. The naming convention for namespaces is the same as for classes, with each word initially capitalized.