Friday 8 February 2013

Watched Videos!!!

       Today was a day with practicing some c# programs, some SQL queries and also i saw some videos on C# console application.
      I found one very good link on C# windows programing which is given below
                         Videos of windows programming in C#

Jagged Array


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace jagged_arrray
{
    class Program
    {
        static void Main(string[] args)
        {
             int[][] arr = new int[4][];
            arr[0] = new int[6];
            arr[1] = new int[7]; 
            arr[2] = new int[8];
            arr[3] = new int[4];
            // printing values of jagged array using nested for
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr[i].Length; j++)
                    Console.Write(arr[i][j] + "");
                Console.WriteLine();
            }
            // assigning values of a jagged array using nested for
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr[i].Length; j++)
                    arr[i][j] = j + 1;
            }
            Console.ReadKey();
           

        }
    }
} 

Two Dimentional Array


//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TD_array
{
    class td_array
    {
        static void Main(string[] args)
        {
            int[,] arr=new int[3,5];
            // Can also initialize the values at the time of declaration
            /*int[,] arr = {{11,12,13,14,15},
                         {21,22,23,24,25},
                         {31,32,33,34,35},
                         };*/

            int x = 0;

            //printing values of 2D array using foreach loop
            foreach (int i in arr)
                Console.Write(i + "  ");
            Console.WriteLine("\n");

            //assigning values to 2D array using nested for
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    x = x + 5;
                    arr[i, j] = x;
                }

            }
            //printing values of 2D array using nested for loop
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                    Console.Write(arr[i, j] + "  ");
                Console.WriteLine();
                Console.ReadKey();

            }
        }
    }
}

Example using Array Class


/* Array class- It is a predefined class of base class libraries present
 * under the System namespace that provides a set of members using which 
 * we can perform operations like Sorting, Reversing,Copying etc*/
//Example of Array class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SD_array2
{
    class sd_array2
    {
        static void Main(string[] args)
        {
            //assining a value at the time of declaration
            int[] arr = { 19, 23, 71, 93, 58, 37, 62, 87, 5, 49, 16, 8, 35, 2 };
            for (int i = 0; i < arr.Length; i++)
                Console.Write(arr[i] + " ");
            Console.WriteLine();
           
            {
                Array.Sort(arr);

                foreach (int i in arr) ;
                Console.Write(i + "   ");
                Console.WriteLine();

                Array.Reverse(arr);
                foreach (int i in arr)
                    Console.Write(i+ "  ");
                Console.WriteLine();

                int[] brr = new int[10];
                Array.Copy(arr, brr, 5);
                Console.Write(i + "  ");
                Console.WriteLine();
            }
            Console.ReadKey();

        }
    }
}

Arrays in C#.Net(Single Dimentional Array)


//
// Example of One dimentional array

// Example of Single dimentional array

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SD_array
{
    class sd_array
    {
        static void Main(string[] args)
        {
            int [] arr= new int[6];
            int x=0;
            //accessing values of an array using for loop

            for(int i = 0; i <6 data-blogger-escaped-10="" data-blogger-escaped-accessing="" data-blogger-escaped-an="" data-blogger-escaped-arr="" data-blogger-escaped-array="" data-blogger-escaped-assigning="" data-blogger-escaped-console.readkey="" data-blogger-escaped-console.write="" data-blogger-escaped-console.writeline="" data-blogger-escaped-each="" data-blogger-escaped-for="" data-blogger-escaped-foreach="" data-blogger-escaped-i="" data-blogger-escaped-in="" data-blogger-escaped-int="" data-blogger-escaped-loop="" data-blogger-escaped-of="" data-blogger-escaped-pre="" data-blogger-escaped-to="" data-blogger-escaped-using="" data-blogger-escaped-values="" data-blogger-escaped-x="">