Friday, September 30, 2011

Working With VISUALSTUDIO .NET -


Working With VISUALSTUDIO .NET – it’s an editor used for developing .net application in any .net language like C#, VB etc. as well as any type of application like console, windows , web etc.

Versions of VISUAL STUDIO .NET –
YEAR
Version
2002
framework 1.0
2003
framework 1.1
2005
framework 2.0
2008
framework 3.5
2010
framework 4.0
  1. TO open VS go to start menu  programs ms visual studio  ms visual studio and click on it to open.
  2. Applications developed under visual studio are known as Projects” where a “project” is the collection of various files or items. To create a project either click on  new project option or go to file menu  select new project, which opens new project window.
  3. under new Project window we need to specify the following details

  •       In the LHS chose the language in which we want to develop the application eg Visual C# .
  •       In the middle chose the type of application we want to develop by choosing a project template. eg – console application.
  •      In the bottom specify a name to the project. eg – SampleProject.
  •      Below project name specify the location where to save the project. eg- C:\CSharp4

          4. click on OK button which creates the project with a default class program under the file Program.cs
          5. When projects are developed in VS by default a Namespace is gets created with same name of the        Project i.e. SampleProject. From now each and every class of the project comes within the same            name space.
NOTE - a Namespace is a logical continuer of types.
          6. Now under Main method of Program Class write the following code.
        Console.WriteLine(“My first Project”);
        Console.WriteLine();
         7. To run the class either presses F5 or ctrl + F5 or Click on start debugging button on top of the                 studio which will saved compile and executes the program.
         8. under VS we find a window known as “ Solution Explorer” used for organizing the complete                      application, which allows to view, add or Delete items under the project, to open ”solution"                      explorer  go to view menu and select “solution Explorer “
         9. to add new class under project open solution explorer  Right click on Project  select add new              item  which opens add new item window select class template in it specify a name in the                      bottom  click on add button which add the class under project eg- class1.cs
     Note – the new class added also comes under the same Namespace.
         10. Now under the class write following code.
static void Main()
{
Console.WriteLine(“second class”);
Console.ReadLine();
}
        11.To run the class open Solution Explorer  right click on the Project  select properties which                opens project property window  under it we find an option  startup objects which lists all the                classes of project that contains a valid main method in them  choose your class and run.

Objects Oriented Programming It is an approach that came into existence in 70th to resolve the drawbacks of traditional procedural approach i.e. security and reusability.
Object Oriented Languages provides Security and Reusability under them we can call a language as OO provided it satisfied the principals of the approach, those are –
  1. Encapsulation.
  2. Abstraction.
  3. Inheritance.
  4. Polymorphism.
As per Encapsulation the code (members) of an OOP has to be enclosed under a wrapper or continuer known as class that provides basic security for contain that is present inside it
Abstraction is all about hiding the complexity, behind the code by providing a set of interfaces used for consuming the functionality. Methods are the best example for abstraction because we never know what is the underling code in it, what we required to know only how to invoke it.

Inheritance - provides code reusability which can be used for consuming members of a class from other class by stabilizing parent/child relation between classes.
Polymorphism  is an approach which tells entities behaves in different ways depending upon the inputs it receives i.e. whenever the input changes the output and the behavior of the entity also changes, which can be implemented using approaches like Overloading and overwriting.

2D array


2D Array
Assigning values to 2D array while Declaration –
int[,]arr = { {11,12,13,14},
{21,22,23,24},
{31,32,33,34},
};
Jagged ArraysThese are also two dimensional that contains rows and columns whereas in two dimensional arrays all the rows will have same no of columns but in a jagged array each row will be having varying or different no of columns.

This are also referred as array of arrays because multiple single dimensional array are combined together to form a new array.
(type)[ ][ ] (name) = new (types)[rows][ ];
int[ ][ ] arr = new int[5][ ];
int [ ] arr = {list of values};
To declare a jagged array in the initial declaration we can only specified the no of rows to the array but not the columns because columns are not fixed.
int[ ][ ] arr = new int[4][ ];
After specifying the no of rows now pointing to each row we need to specify the no. of columns to the row.
int [ ] [ ] arr = new int[4][ ];
arr[0] = new int[5];
arr[1] = new int[6];
arr[2] = new int[8];
arr[3] = new int[4];

        Program
For Assigning Values to Jagged Array while Declaration –
int [ ][ ]arr = {
new int[3]{11,12,13},
new int[5]{21,22,23},
new int[4]{31,32,33},
new int[3]{41,42}
};
Command Line Parameters In the execution of a program it may required from values that needs to supplied in rum time where the values can be supplied in two diff ways –
  1. The program prompts for a value for which we supply the value and within the program the value is captured using reed line method.
  2. In the second case you can supply a list of values for any program at the of execution from the command prompt besides the program name, separating each value with a space.
    using System;
    class ParamsDemo
    {
    static void Main(string[] args)
    {
    foreach(string str in args)
    Console.WriteLine(str);
    }
    }
    For the above program while executing the program we can supply a list of values as command line parameters where all those values will be tacking into the string array of main method. To check the execute the above program as following.
    C:\csharp4>ParamsDemo 100 hello 3.14 true
    Program –
using System;
class AddParams
{
static void Main(string[] args)
{
int sum = 0;
foreach(string str in args)
sum += int.Parse(str);
Console.WriteLine(sum);
}
}