Tuesday, August 9, 2016

What is array in C#



An array store fixed-size sequential collection of elements of the same datatype. It is used to store the collection of data of same data type at contiguous memory locations.

Declaration of array –
Datatype [ ] arrayname;

Datatype specify the data of elements in the array.
[ ] specify the size of the array.
And arrayname is the name of array.

Initializing an Array -
An array is the reference type so we need new keyword to create the instance of the array. For example –
double d= new double [10];

Assigning value to an Array –
We can assign the value to an array by using the index number. For example –
double d= new double [10];
d[0]=100;

we can also assign the value to an array at the time of declaration –
double[ ] d={10,15,20,25,30}

We can also create and initialize the array as the following ways
int[ ] mark=new int[5] {20,21,22,23,29}
or
int[] mark=new int[ ] {22,24,26,28,29}

The Example of the array is given below:

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

namespace ConsoleApplication18
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] n = new int[10];
            int i, j;
            for (i = 0; i < 10; i++)
            {
                n[i] = i + 10;
            }
            for (j = 0; j < 10; j++)
            {
                Console.WriteLine("index[{0}] = {1}", j, n[j]);
            }
            Console.ReadKey();
        }
    }
}
 
Output - 
Following are the some important concept related to the array.

Multi-dimensional arrays – C# support multi-dimensional arrays. It is also called two dimensional arrays.

Jagged arrays – The array of array is also jagged arrays.

Passing arrays to functions – We can pass a function to an array by specifying the array name without an index.

Param arrays – Param arrays is used to pass unknown number of parameter to a function

The array class – The array class provides the various properties and methods by define system name space.

Monday, August 8, 2016

SQL Select Top Clause



The SQL select top clause is used to return the number of records. It is very helpful when we want to fetch the record from a very large table that contains thousands of records.

Example –
Firstly we create a table with name “emp”-

 Select top 2 * from emp

Output - 



SQL Select TOP PERCENT Example -

Select top 50 percent * from emp
Output -



Friday, August 5, 2016

SQL AND & OR operators



The SQL AND & OR operators used to filter the record that is based on one or more condition.
The AND operator used to show the record if both first and second condition are true.
The OR operator used to show the record if either the first condition OR second condition is true.
Example – Firstly we create the table “emp

 
AND operator Example –

select * from emp where id='1' AND name='sachin'

Output – 

OR operator Example –

select * from emp where id='1' OR name='pramod'

Output – 
                                                               Author - Sachin Pathak