Friday, 13 February 2015

C# Structure Volume Of Cuboid Program(User input)

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

namespace areaofrectangle
{
       struct Cuboid
        {
            int length;
            int breadth;
            int height;

            Cuboid(int x, int y,int z)
            {
                length = x;
                breadth = y;
                height = z;
            }
          int Volume()
            {
               return length * breadth*height;
            }

            public static void Main(string[] args)
            {
                Console.WriteLine("Enter the value of x");
                int x = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter the value of y");
                int y = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter the value of z");
                int z = Convert.ToInt32(Console.ReadLine());
                Cuboid vol= new Cuboid(x,y,z);
                Console.WriteLine("Volume of Cubid is"+"="+vol.Volume());



             
                Console.ReadKey();
            }
        }
}

Output:

Saturday, 19 April 2014

The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.

Hello Friends,Today,I have solved this below grid view error which generally comes when we use custom code to populate gridview in asp.net.So,I have added some code to resolve this....Error as follows:
Some points we should remember before bind grid view to custom datasource.They are
1.Create a session,use Ispostback ,and place inside page_load event of page.
2.In PageChangingIndex event bind datasource and  handle pageIndex.


The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.

Here is Error free code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Default3 : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\Dev Sharma\\Documents\\Visual Studio 2010\\WebSites\\c2Chart\\App_Data\\northwnd.mdf;Integrated Security=True;User Instance=True");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["CustReport"] = null;
        }
        if (Session["CustReport"] != null)
        {
            GridView1.DataSource = Session["CustReport"];
            GridView1.DataBind();
        }
       
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //SqlCommand cmd = new SqlCommand();
        //cmd.Connection = con;
        con.Open();
        SqlDataAdapter da = new SqlDataAdapter("Select * from Customers", con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        Session["CustReport"] = ds;
        con.Close();

    }
  

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource = Session["CustReport"];
        GridView1.DataBind();
    }
}

 

Friday, 31 January 2014

C# leap year check program-----------|||||||||||||||||||||

C# Code:

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

namespace leapYearCheck
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the year");

            int year = Convert.ToInt32(Console.ReadLine());
            if (DateTime.IsLeapYear(year))
            {
                Console.WriteLine("Leap Year");
            }
            else
                Console.WriteLine("Not a Leap Year");
            Console.ReadKey();
        }
     

    }
}

Output:





C# program to check even and odd number---------|||||||||||||

C#:

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

namespace evenodd
{
    class Program
    {
        static void Main(string[] args)
        {
            int number;
            Console.WriteLine("Enter any number");
            number = Convert.ToInt32(Console.ReadLine());
            if (number == 0)
            {
                Console.WriteLine("The number is neither even nor odd number");
            }
            else
            {
                int j = number % 2;
                if (j == 0)
                {
                    Console.WriteLine("Number is even");

                }
                else
                    Console.WriteLine("Number is odd");

            }
            Console.ReadKey();
        }
    }
}

Output:

Monday, 27 January 2014

Data Types in C#----------------|||||||||

Data types specify the size and type of values that can be stored.C# is a language rich in data types.
The types in C# are primarily divided into categories:
* Value type
* Reference types

But how these two types are differ with each other.Let us see

* Where they are stored in the memory
* How they behave in the context of assignment statements

Value types which is fixed in size(fixed length) are store on the stack.When a value of a variable is assigned to another variable,the value is actually copied.These means that two identical copies of the value are available in memory.

Reference types which are of variable length are stored on the heap, and when an assignment between two reference variables occurs, only the reference is copied; the actual value remains in the  same memory location.This means that there are two references to a single value.

A third categories of types called pointers is available for use only in unsafe code.

Saturday, 18 January 2014

C# Regular Expression Program------------||||||||||||||||||||||

C# Code:


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

namespace regularExpression
{
    public class Program
    {


        static void Main(string[] args)
        {
            String str;
            str = "Amar,Akbar,Anthony are friends!";
            Regex reg = new Regex(" |,");
            StringBuilder sb = new StringBuilder();
            int count = 1;
            foreach (String sub in reg.Split(str))
            {
                sb.AppendFormat("{0}:{1}\n", count++, sub);
            }
            Console.WriteLine(sb);
            Console.ReadKey();
        }
    }
}

Output:



Monday, 13 January 2014

C# ThreadPool Program-----------|||||||||||||||||||||||||

C# Code:

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

namespace ThreadPoolProgram
{
    public class ThreadPoolTest
    {
        public static object showThread = new object();
        public static int runThread = 20;
        public static void Main()
        {
            for (int i = 0; i < runThread; i++)
            {
                ThreadPool.QueueUserWorkItem(Display, i);
            }
            Console.WriteLine("Running 20 Threads to one by one and stopping them after 3 seconds.\n");
            lock (showThread)
            {
                while (runThread > 0)
               
                    Monitor.Wait(showThread);
               
            }
            Console.WriteLine("All threads stopped succesfully!");
            Console.ReadLine();
        }
        public static void Display(object objThread)
        {
            Console.WriteLine("Started Thread:" + objThread);
            Thread.Sleep(3000);
            Console.WriteLine("Ended Thread:" + objThread);
            lock (showThread)
            {
                Monitor.Pulse(showThread);
            }



        }

    }
}

Output: