Wednesday, July 15, 2015

Adding Dynamic Rows in GridView with DropDownLists in ASP.Net

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
//using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Specialized;

namespace autorowgenaration
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        private ArrayList ddlist()
        {
            ArrayList arl = new ArrayList();
            arl.Add(new ListItem("feel", "1"));
            arl.Add(new ListItem("feel2", "2"));
            return arl;

        }
        private void fildrop(DropDownList ddl)
        {
            ArrayList arl = ddlist();
            foreach (ListItem item in arl)
            {
                ddl.Items.Add(item);
            }
        }
        protected void setfirstrow()
        {
            DataTable dt = new DataTable();
            DataRow dr = null;
            dt.Columns.Add(new DataColumn("rowno", typeof(string)));
            dt.Columns.Add(new DataColumn("col1", typeof(string)));
            dt.Columns.Add(new DataColumn("col2", typeof(string)));
            dt.Columns.Add(new DataColumn("col3", typeof(string)));
            dt.Columns.Add(new DataColumn("col4",typeof(string)));
            dr = dt.NewRow();
            dr["rowno"] = 1;
            dt.Rows.Add(dr);
            ViewState["currenttable"] = dt;
            GridView1.DataSource = dt;
            GridView1.DataBind();
            DropDownList ddl1 = (DropDownList)GridView1.Rows[0].Cells[1].FindControl("ddlfeelings");
            DropDownList ddl2 = (DropDownList)GridView1.Rows[0].Cells[2].FindControl("ddlno");
            DropDownList ddl3 = (DropDownList)GridView1.Rows[0].Cells[3].FindControl("ddlday");
            DropDownList ddl4 = (DropDownList)GridView1.Rows[0].Cells[4].FindControl("ddlspecifications");
            fildrop(ddl1);
            fildrop(ddl2);
            fildrop(ddl3);
                fildrop(ddl4);
        }
        protected void addnewrow()
        {
            if (ViewState["currenttable"] != null)
            {
                DataTable dtcurrenttable = (DataTable)ViewState["currenttable"];
                DataRow drCurrentRow = null;
                if (dtcurrenttable.Rows.Count > 0)
                {
                    drCurrentRow = dtcurrenttable.NewRow();
                    drCurrentRow["rowno"] = dtcurrenttable.Rows.Count + 1;
                    dtcurrenttable.Rows.Add(drCurrentRow);
                    ViewState["CurrentTable"] = dtcurrenttable;

                    for (int i = 0; i < dtcurrenttable.Rows.Count - 1; i++)
                    {
                        DropDownList ddl1 = (DropDownList)GridView1.Rows[i].Cells[1].FindControl("ddlfeelings");
                        DropDownList ddl2 = (DropDownList)GridView1.Rows[i].Cells[2].FindControl("ddlno");
                        DropDownList ddl3 = (DropDownList)GridView1.Rows[i].Cells[3].FindControl("ddlday");
                        DropDownList ddl4 = (DropDownList)GridView1.Rows[i].Cells[4].FindControl("ddlspecifications");


                        dtcurrenttable.Rows[i]["col1"] = ddl1.SelectedItem.Text;
                        dtcurrenttable.Rows[i]["col2"] = ddl2.SelectedItem.Text;
                        dtcurrenttable.Rows[i]["col3"] = ddl3.SelectedItem.Text;
                        dtcurrenttable.Rows[i]["col4"] = ddl4.SelectedItem.Text;
                    }

                    GridView1.DataSource = dtcurrenttable;
                    GridView1.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }


            setpreviousdata();
        }
        protected void setpreviousdata()
        {
            int rowIndex = 0;
            if (ViewState["currenttable"] != null)
            {
                DataTable dt = (DataTable)ViewState["currenttable"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {

                        DropDownList ddl1 = (DropDownList)GridView1.Rows[rowIndex].Cells[1].FindControl("ddlfeelings");
                        DropDownList ddl2 = (DropDownList)GridView1.Rows[rowIndex].Cells[2].FindControl("ddlno");
                        DropDownList ddl3 = (DropDownList)GridView1.Rows[rowIndex].Cells[3].FindControl("ddlday");
                        DropDownList ddl4 = (DropDownList)GridView1.Rows[rowIndex].Cells[3].FindControl("ddlspecifications");
                        fildrop(ddl1);
                        fildrop(ddl2);
                        fildrop(ddl3);
                        fildrop(ddl4);

                        if (i < dt.Rows.Count - 1)
                        {
                            ddl1.ClearSelection();
                            ddl1.Items.FindByText(dt.Rows[i]["col1"].ToString()).Selected = true;

                            ddl2.ClearSelection();
                            ddl2.Items.FindByText(dt.Rows[i]["col2"].ToString()).Selected = true;

                            ddl3.ClearSelection();
                            ddl3.Items.FindByText(dt.Rows[i]["col3"].ToString()).Selected = true;
                            ddl4.ClearSelection();
                            ddl4.Items.FindByText(dt.Rows[i]["col4"].ToString()).Selected = true;
                        }

                        rowIndex++;
                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                setfirstrow();
            }
        }
     
        protected void btnadd_Click(object sender, EventArgs e)
        {
            addnewrow();
        }
    }
}
--------------aspx--------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="autorowgenaration.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            width: 182px;
        }
        .style3
        {
            width: 130px;
        }
        .style4
        {
            width: 143px;
        }
        .style5
        {
            width: 174px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <table id="tblfeel" class="style1">
        <tr>
            <td class="style2">
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
                <Columns>
                <asp:BoundField DataField="rowno" HeaderText="sno" />
                <asp:TemplateField HeaderText="feelings">
                <ItemTemplate>
                <asp:DropDownList ID="ddlfeelings" runat="server">
                <asp:ListItem>i am feeling</asp:ListItem>
                </asp:DropDownList>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="no">
                <ItemTemplate>
                <asp:DropDownList ID="ddlno" runat="server">
                <asp:ListItem>--no--</asp:ListItem>
                </asp:DropDownList>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="day">
                <ItemTemplate>
                <asp:DropDownList ID="ddlday" runat="server">
                <asp:ListItem>Day</asp:ListItem>
                </asp:DropDownList>
                 </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="specifications">
                 <ItemTemplate>
                 <asp:DropDownList ID="ddlspecifications" runat="server">
                 <asp:ListItem>Specification</asp:ListItem>
                 </asp:DropDownList>
                 </ItemTemplate>
               <FooterTemplate>
               <asp:Button ID="btnadd" runat="server" Text="Add new row" />
               </FooterTemplate>
                </asp:TemplateField>
                </Columns>
                </asp:GridView>
            </td>
            <td class="style3">
                &nbsp;</td>
            <td class="style4">
                &nbsp;</td>
            <td class="style5">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
    <asp:Button ID="btnadd" runat="server" onclick="btnadd_Click" Text="ADD" />
    </form>
</body>
</html>

Tuesday, June 16, 2015

changing theme dynamicaly in master page

To implement this first create new website in visual studio after that right click on your website and select Add New Item after that select Master page and click OK. Now master page added to your application. Now again right click on your website and select Add ASP.NET Folder under that selectTheme now App_Themes folder will add to your application. Now right click on App_Themes folder and create two new Asp.net folders and give names as “Blue” and “Red”. Now select Blue folder under that add one skin file and one css file same way add skin file and css file in Red folder also. Here we need to use Page_PreInit event in all the pages wherever we need to change themes dynamically for that reason instead of writing this same event in all the pages we need to create new class file and give name as ThemeClass and write following code.

Over all our structure of the application will be like this


---------------master page-----------------------------------

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            height: 237px;
        }
        .style3
        {
            height: 237px;
            width: 46px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     
        <table class="style1">
            <tr>
                <td align="center" colspan="2">
                    article</td>
            </tr>
            <tr>
                <td class="style3">
                </td>
                <td class="style2">
                    <asp:ContentPlaceHolder ID="head" runat="server">
                    </asp:ContentPlaceHolder>
                    <b>Click Button to change Theme</b><br />
<asp:Button ID="btnBlue" runat="server" Text="Blue" BackColor="#44BCED" Font-Bold="true"
                        onclick="btnBlue_Click" />
<asp:Button ID="btnRed" runat="server" Text="Red" BackColor="Red" Font-Bold="true"
                        onclick="btnRed_Click" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;</td>
            </tr>
        </table>
     
    </div>
    </form>
</body>
</html>

-------------------------------------------------master page.cs----------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MasterPage : System.Web.UI.MasterPage
{
    public class ThemeClass: System.Web.UI.Page
    {
       
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnBlue_Click(object sender, EventArgs e)
    {

        Session["Theme"] = btnBlue.Text;
        Server.Transfer(Request.FilePath);
      
    }
    protected void btnRed_Click(object sender, EventArgs e)
    {
       Session["Theme"]=btnRed.Text;
       Server.Transfer(Request.FilePath);
    }
}
--------------------------------default.aspx-----------------------------------------
<%@ Page Title="" Theme="blue" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
 <asp:Panel ID="pnllogin" runat="server" Height="148px" 
        style="margin-left: 529px" BackColor="#33CCFF" BorderColor="#CC00CC" 
        BorderStyle="Solid" BorderWidth="5px" ForeColor="#0099CC" 
    Width="323px" >
        <br />
        <br />
        &nbsp;<asp:Label ID="lblname" runat="server" ForeColor="Blue" Text="NAME"></asp:Label>
        &nbsp;
        <asp:TextBox ID="name" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Label ID="lblpassword" runat="server" ForeColor="Blue" Text="Password"></asp:Label>
        <asp:TextBox ID="txtpassword" runat="server"></asp:TextBox>
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="btnlogin" runat="server" Height="26px" Text="LOG IN" 
            Width="63px" />
        &nbsp;<asp:Button ID="btnregister" runat="server" Text="REGISTER" />
    </asp:Panel>
    <asp:GridView ID="GridView1" runat="server" BorderColor="#CC0099" 
        BorderStyle="Solid" BorderWidth="5px" AutoGenerateColumns="False">
        <Columns>
           
            <asp:TemplateField HeaderText="Title">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("c_Articles_Name") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("c_Articles_Name") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Category">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" 
                        Text='<%# Bind("c_Articles_Details") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("c_Articles_Details") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Author">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" 
                        Text='<%# Bind("c_CAND_AUTHENTICATION_UserId") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" 
                        Text='<%# Bind("c_CAND_AUTHENTICATION_UserId") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="PostedDate">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("c_Articles_Date") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("c_Articles_Date") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
           
        </Columns>
    </asp:GridView>
</asp:Content>
-------------------------------------------------------default.aspx.cs----------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    
        protected void page_preInit(object sender, EventArgs e)
        {
            if (Session["Theme"] != null)
            {
                Page.Theme = Session["Theme"].ToString();
            }
        }
    
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}
-------------------------------stylesheet-----------------------------
body
{
font-size: 15pt;
color: #000000;
background-color: Red;
}
--------------------------------skinfile-------------------------------
<asp:Label runat="server"  Font-Bold="true" Font-Italic="true" />
<asp:Textbox runat="server"  BackColor="Orange" BorderColor="DarkCyan" BorderStyle="Dotted" BorderWidth="2" />

Sunday, May 31, 2015

update and delete gridview rows

code behind:
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;

namespace gridviewedit
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        SqlConnection _con = new SqlConnection("Data Source=db205.my-hosting-panel.com;Initial Catalog=goggery_sample;Persist Security Info=True;User ID=goggery_sample;Password=sample1.0");
         protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }
         protected void bind()
         {
             SqlCommand _cmd = new SqlCommand("select * from emp_nandu", _con);
             DataSet _ds = new DataSet();
             SqlDataAdapter _da = new SqlDataAdapter(_cmd);
             _da.Fill(_ds);
             GridView1.DataSource = _ds;
             GridView1.DataBind();
         }
   
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
            int EMP_ID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
            Label Lbl = (Label)row.FindControl("lblemp_id");
            TextBox txtename = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtename");
            TextBox txtmanager = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtmanager");
            TextBox txtdept = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtdept");
            TextBox txtsal = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtsal");
           
            GridView1.EditIndex = -1;
 0    
SqlCommand _cmd = new SqlCommand("update emp_nandu set ENAME='"+txtename.Text+"',MANAGER_ID='"+txtmanager.Text+"',DEPT='"+txtdept.Text+"', SAL='"+txtsal.Text+"' where EMP_ID="+EMP_ID+"", _con);
_con.Open();
_cmd.ExecuteNonQuery();
_con.Close();
bind();
     

        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            bind();

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values["EMP_ID"].ToString());
          //  string username = GridView1.DataKeys[e.RowIndex].Values["UserName"].ToString();
            _con.Open();
            SqlCommand _cmd = new SqlCommand("delete from emp_nandu where EMP_ID='"+id+"'", _con);
            _cmd.ExecuteNonQuery();
            _con.Close();
            bind();
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex = -1;
            bind();

        }

     
    }
}
asp page code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="gridviewedit.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body style="height: 257px; width: 627px">
    <form id="form1" runat="server">
    <div>
   
    </div>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="EMP_ID"
        onrowcancelingedit="GridView1_RowCancelingEdit"
        onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
        onrowupdating="GridView1_RowUpdating"
        Height="211px"
        Width="617px" >
        <Columns>
       
            <asp:TemplateField HeaderText="EMP_ID">
                <EditItemTemplate>
                    <asp:TextBox ID="txtemp_id" runat="server" Text='<%# Eval("EMP_ID") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblemp_id" runat="server" Text='<%# Eval("EMP_ID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="ENAME">
                <EditItemTemplate>
                    <asp:TextBox ID="txtename" runat="server" Text='<%# Eval("ENAME") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblename" runat="server" Text='<%# Eval("ENAME") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="MANAGER">
                <EditItemTemplate>
                    <asp:TextBox ID="txtmanager" runat="server" Text='<%# Eval("MANAGER_ID") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblmanager" runat="server" Text='<%# Eval("MANAGER_ID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="DEPT">
                <EditItemTemplate>
                    <asp:TextBox ID="txtdept" runat="server" Text='<%# Eval("DEPT") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lbltext" runat="server" Text='<%# Eval("DEPT") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="SAL">
                <EditItemTemplate>
                    <asp:TextBox ID="txtsal" runat="server" Text='<%# Eval("SAL") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblsal" runat="server" Text='<%# Eval("SAL") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ShowCancelButton="true" />
            <asp:CommandField ShowEditButton="true" />
            <asp:CommandField ShowDeleteButton="true" />
        </Columns>
    </asp:GridView>
    </form>
</body>
</html>

Thursday, May 14, 2015

logfile in c#

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;
using System.IO;

namespace logfile
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        SqlConnection _con = new SqlConnection("Data Source=db205.my-hosting-panel.com;Initial Catalog=goggery_sample;User ID=goggery_sample;Password=sample1.0");
        protected void Page_Load(object sender, EventArgs e)
        {

        }
     

        public void LogFile(string sExceptionName, string sEventName, string sFormName)
        {

            StreamWriter log;

            if (!File.Exists("logfile.txt"))
            {

                log = new StreamWriter("E:\\nandu\\logfile.txt");

            }

            else
            {

                log = File.AppendText("E:\\nandu\\logfile.txt");

            }

            // Write to the file:

            log.WriteLine("Data Time:" + DateTime.Now);

            log.WriteLine("Exception Name:" + sExceptionName);

            log.WriteLine("Event Name:" + sEventName);

            //log.WriteLine("Control Name:" + sControlName);

            //log.WriteLine("Error Line No.:" + nErrorLineNo);

            log.WriteLine("Form Name:" + sFormName);

            // Close the stream:

            log.Close();

        }
       

        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            try
            {
                SqlCommand _cmd = new SqlCommand("insert into log_nandu values('" + txtname.Text + "','" + txtcourse.Text + "','" + txtfee.Text + "')", _con);
                _con.Open();
                _cmd.ExecuteNonQuery();
                _con.Close();
            }
            catch (Exception exe)
            {

                //call LogFile method and pass argument as Exception message, event name, control         name, error line number, current form name

                LogFile(exe.Message, exe.ToString(),this.Page.ToString());

            }
        }


    }
}

Monday, March 9, 2015

interface c#

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

namespace inter
{

    public interface operations
    {

        void operation();
        int add();
        int sub();
        //int mult();
    }
    public class math : operations
    {
        private int x1;
        private int y1;

     
        public math(int x, int y)
        {
            x1 = x;
            y1 = y;

        }
        public int add()
        {
            return x1 + y1;
        }
        public int sub()
        {
            return x1 - y1;
        }
        public void operation()
        {
            Console.WriteLine("x1: {0}", x1);
            Console.WriteLine("y1:{0}", y1);
            Console.WriteLine("add:{0}", add());
            Console.WriteLine("sub:{0}", sub());
        }
    }
        public class math2 : operations
        {
            private int a;
            private int b;

            public math2(int c, int d)
            {
                a = c;
                b = d;
            }
            public int mult()
            {
                return a * b;
            }
            public void operation()
            {
                Console.WriteLine("a: {0}", a);
                Console.WriteLine("b:{0}", b);
                Console.WriteLine("add:{0}", mult());
               
            }
        }
   
    class Tester
    {
        static void Main(string[] args)
        {
            math madd = new math(20, 30);
            math2 m2= new math2(10,30);
            madd.operation();
            m2.operation();
            Console.ReadKey();
        }
    }
}



operator over loading

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

namespace oprovr
{
    class program
    {
     
       
       
            public int fun(int a, int b)
            {
               
                return(a+b);
            }
            public int fun(int a, int b, int c)
            {
                return(a+b+c);
            }
            public string fun(string a, string b)
            {
                return(a+b);
            }
   
        static void Main(string[] args)
        {
            //Console.WriteLine("enter values");
           //int a=Convert.ToInt32(Console.ReadLine());
           //int b=Convert.ToInt32(Console.ReadLine());
           program f= new program();
            int c=f.fun(3,5);
            int b=f.fun(1,2,3);
            string s = f.fun("over", "loading");
            Console.WriteLine("two sum" +c);
            Console.WriteLine("three sum" +b);
            Console.WriteLine(s);


            Console.ReadKey();
        }
       

    }
}

polyndrom using for loop c#

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

namespace polyn
{
    class Program
    {
        static void Main(string[] args)
        {
            string s,revs="";
            Console.WriteLine("enter string");
            s = Console.ReadLine();
            for (int i = s.Length-1 ; i>= 0; i--)
            {
                revs += s[i].ToString();
            }


            if (revs == s)
            {
                Console.WriteLine("given string is polyndrum \ngiven string is {0}\nrevs string is {1}", s, revs);
            }
            else
            {
                Console.WriteLine("given string is not polyndrum \ngiven string is {0}\nrevs string is {1}", s, revs);
            }
            Console.ReadKey();

        }
    }
}