Sunday, September 9, 2012

Saturday, September 8, 2012

Working with Array List PART 2


using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList arr = new ArrayList();
            arr.Add("Uday");
            arr.Add("Vijay");
            Console.WriteLine("The count in the arraylist is " + arr.Count);
            arr.Add("Shiva");
            arr.Add("Raju");
// Whenever we add Five Element the Capacity will be double, the default capacity of 
//ArrayList is 4
            Console.WriteLine("the capacity in the arraylist is " + arr.Capacity);
            arr.Add("Srikanth");
            Console.WriteLine("the capacity in th arraylist is " + arr.Capacity);
            arr.Add("Srinu");
            arr.Add("Trisha");
            arr.Add("Illeana");
            arr.Add("Samantha");
            Console.WriteLine("the capacity in th arraylist is " + arr.Capacity);
            arr.Add("Chiranjeevi");
            arr.Add("Prasad");
            arr.Add("Venkatesh");
            arr.Add("Murthy");
            arr.Add("Charan");
            arr.Add("Mahesh");
            arr.Add("Pawan");
            Console.WriteLine("The capacity in th arraylist is " + arr.Capacity);
            arr.Add("AlluArjun");
            Console.WriteLine("the capacity in th arraylist is " + arr.Capacity);
            Console.ReadKey();
        }
    }
}


Output


Count:


It is used to count the total no of elements which are been inserted.







Output:




Count: It is used to Count the Total no of elements which are inserted.


Contains: It is used to check wheather the element exists in the ArrayList or Not.







Output:




Insert Method;


It will insert the element in the specified location of the index in the ArrayList.




AddRange 


It will add the collections of elements in the object as individual objects in the Array List





Output:



RemoveAt


It will remove the object as specified in the argument.







Output




Working with ArrayList PART 1

ArrayList

File->New-> Project-Console Application


using System.Collections;


It is the namespace which  is used.




Output




Add Method

It will add the element as object in the Array List. These Objects are stored in heap.

Saturday, September 1, 2012

GridView with DataSet ,DataTable, DataReader

DataBase Design


Default.aspx


Default.aspx.cs


protected void Button1_Click(object sender, EventArgs e)
    {
        /* dataset */
        con = new SqlConnection("user id=sa;password=uday;database=uday;data source=localhost");
        cmd=new SqlCommand("select *from customers", con);
        con.Open();
        da=new SqlDataAdapter(cmd);
        ds = new DataSet();
        da.Fill(ds,"customers");
        GridView1.DataMember = "customers";
        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();
    }


protected void Button3_Click(object sender, EventArgs e)

    {
        /* DataTable */
        con = new SqlConnection("user id=sa;password=uday;database=uday;data source=localhost");
        cmd = new SqlCommand("select *from customers", con);
        con.Open();
        da = new SqlDataAdapter(cmd);
        dt = new DataTable();
        da.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        con.Close();
    }

protected void Button2_Click1(object sender, EventArgs e)
    {
        /* datareader */
        con = new SqlConnection("user id=sa;password=uday;database=uday;data source=localhost");
        cmd = new SqlCommand("select *from customers", con);
        con.Open();
        SqlDataReader dr;
        dr = cmd.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        con.Close();
    }

Output:


Friday, August 31, 2012

Access Specifiers in C#.

They are used to define scope of the Class or its Members i,e who can access it and who cannot Access it.

Here we will discuss about each access specifier with an example. 


.Net Supports five Access Specifiers.


1 Public.

2 Private.
3 Protected.
4 Internal.
5 Protected Internal.


public:


So any member declared as public can be accessed from the outside the class.


We can access from other class using object reference.


Example 


File-New- Project- Console Application.






In the above example we have created a object in Derived Class , since the variable is public it can be accessed from outside the class.

output





private


Members declared as private are not Accessible outside the class.

A class under Namespace cannot be declared as private.


Example 




Output:




Example for Public and Private Access Specifier.



output


2 Example





output 






Protected

If the members are declared as  protected , then they can be accessed only From the child class., it is same as private.


Note: A class under Namespace cannot be declared as private. 

This access specifier is used when we need to use Inheritance in the program.



output




Another Example of working with Protected Access Specifier.



Internal


Members are declared as internal under a class than they r accessible only with in the Project either from the Child Class or a Non Child Class. These are accessible only within the Assembly.


internal  is the default Access Specifier for the Class.




output




Protected Internal 


Members declared as ProtectedInternal under a Class enjoys Dual Scope. i,e with the project they behave as internal members and provide access to all the classes, outside the project they change to Protected and still provide access to there child classes.







Output:













Add a new project under the solution of type Console Application, name it as ConsoleApplication2 & rename the default file Program.cs as Four.cs so that class name also changes as Four, now write the following code in it by adding the reference of ConsoleApplication1 assembly from its physical location.





Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...