Thursday, 24 April 2014

.NET Introduction

Introduction .NET framework:-


The .NET Framework, introduced by Microsoft, aims at integrating various programming languages and services. 

The .NET Framework is designed to make significant improvements in code reuse, code specialization, resource management, multilanguage development, security, deployment, and administration. 

The .NET Framework consists of all the technologies that help in creating and running robust, scalable, and distributed applications.

The .NET suite consists of:

  • .NET Products
  • .NET Services
  • .NET Framework

.NET Products:

.NET products aim at allowing developers to create applications, which are capable of interacting seamlessly with each other. 
All .NET products use eXtensible Markup Language (XML) for describing and exchanging data between applications.
An example of a .NET product is Visual Studio .NET.


.NET Services:

.NET helps you to create software as Web services. A Web Service is an application or business logic that is accessible through standard Internet protocols such as Hypertext Transfer Protocol (HTTP) and Simple Object Access Protocol (SOAP). You can identify the service by a Uniform Resource Locator (URL).

Microsoft has come up with its own set of Web services, known as My Services.

This service allows users to access data by linking calendars, phonebooks, address books, and personal references to the passport authentication service.

The various components of the .NET Framework are:

  • Common Language Runtime
  • The .NET Framework Class Library
  • User and Program Interfaces


CLR is the environment where all programs in .NET are executed. 

CLR provides services such as code compilation, memory allocation, and garbage collection. 

CLR allows the execution of code across different platforms by translating code into Intermediate Language (IL).

IL is a low level language that the CLR understands. 

IL is converted into machine language during execution by the JIT compiler. During JIT compilation, code is also checked for type safety. 

Type safety ensures that objects are always accessed in a compatible way.








Static

Static variables and static functions:-


The keyword 'static' means that only one instance of a given variable exists for a class.

Static variables are used to define constants because their values can be retrieved by invoking the class without creating an instance of it.

Static variables can be initialized outside the member function or class definition.

Unlike other member variables, only one copy of the static variable exists in the memory for all the objects of that class.

Static functions can access only static variables.

Static functions exist even before the object is created.


Example:-

 class Test
    {
        public int numberI;
        public static int numberII;
        public void MethodI()
        {
            numberI = 10;
            numberII = 20;

        }
        public static void MethodII()
        {
            numberI++; // Error Static Method only static Member Access
            numberII++;
        }
    }


Calling Methods in C#


Method Calling:-

When the methods are declared with parameters, they should be called with parameters. The methods with parameters are called by passing the value using the following mechanism:

  • Value
  • Reference
  • Output
Value: The parameters passed by value creates a separate copy in the memory. The following example shows the parameters passed by value:

void CalculateSum( int num1, int num2)
{
   //…
}

void Accept()
{
    int val1=10;
    int val2=2;
    CalculateSum(val1,val2);
}

Reference: The parameters passed by reference does not creates a separate copy of the variable in the memory. A reference parameter stores the memory address of the data member passed. The following example shows the parameters passed by reference:

void CalculateSum( ref int num1,ref int num2)
{
//…
}
void Accept()
{
int val1=10;
int val2=2;
CalculateSum( ref val1,ref val2);
}

Output: The output parameters are used to pass the value out of the method. The following example shows the parameters passed by reference:

void CalculateSum( ref int num1,ref int num2, out int result)
{
     result=num1+num2;
}
void Accept()
{
int val1=10;
int val2=2;
int recieveVal;
CalculateSum( ref val1,ref val2,out recieveVal);
}





Monday, 21 April 2014

What is Method

Method:- A method is a set of one or more program statements, which can be executed by referring to the method name.

Define methods:-
<Access specifier> <Return Type> <Method Name>(Parameter List)
{
Method Body
}


The elements of the method declaration include the method name, the parameters list, the return type, and the method body.

The following are the elements of a method:
Access specifier
Return type
Method name
Parameter list
Method body

Example:-using System;
  class Test
  {
     static void Main(string[] args)
     {
          Myclass obj = new Myclass();
          obj.Show();
          Console.ReadLine();
     }
  }
class Myclass
{
    public void Show()
    {
        Console.WriteLine("Show Method");
     }
}

Data Abstraction & Encapsulation

Data Abstraction & Encapsulation:Abstraction and encapsulation are important features of any object-oriented programming language.Abstraction involves extracting only the relevant information.Encapsulation involves packaging one or more components together.Encapsulation literally means ‘to enclose in or as if in a capsule’.Encapsulation is defined as the process of enclosing one or more items within a physical or logical package.It involves preventing access to nonessential details.


Access specifier:-An access specifier defines the scope of a class member.A class member refers to the variables and functions in a class.A program can have one or more classes.You may want some members of a class to be accessible to other classes.But, you may not want some other members of the class to be accessible outside the class.public private protected internalprotected internal








Sunday, 20 April 2014


Saturday, 19 April 2014

what is namespace

Namespace:-  
  • A namespace contains a set of related classes. 
  • A namespace contains a set of related objects.
Namespace  Namespace_Name
 {  

     class    method    variable
}