22 Sep 2017

what is copy constructor in C sharp with example


copy constructor can be used to create an object copy the value from another object it is called copy constructor.

Example-
                     Suppose that if you want to create a new object you wand to copy the value another object. 

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

namespace what_is_copy_constructor
{
  public class Rock
    {
        public string Name;
        public int Age;
        public Rock(string X, int Y)//instance constructor //
        {
            Name = X;
            Age= Y;
        }
        public Rock(Rock Obj)//Declaring Copy Constructor//  

        {
            Name = Obj.Name;
            Age = Obj.Age;
        }
        public void print()
        {
            Console.WriteLine("{0},{1}", Name, Age);
        }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            Rock Obj = new Rock("Rock Programmer",25); //create the new object

            Rock Obj1 = new Rock(Obj);//copy the object
            Obj.print();
            Obj1.print();
            Console.ReadKey();

        }
    }
}
out put:-

Read Complete

What is Parameterized constructor in C Sharp


A constructor is passing the argument is called Parametureid constructor.

Example of  Parameterized constructor

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

namespace What_is_Parameterized_Constructor
{
    class Devesh
    {
        int a, b;
        public Devesh(int X, int Y)
        {
            a = X;
            b = Y;
        }
        static void Main(string[] args)
        {
            Devesh dd = new Devesh(500, 1500);
            Console.WriteLine("Print the value X:" +dd.a);
            Console.WriteLine("Print the value Y:" + dd.b);
            Console.ReadKey();
        }
    }
}

output:-

Read Complete

What is Default Constructor in C sharp


A Constructor not Parameterized is called a default Constructor.

Example of Default Construtor:-

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

namespace what_is_default_constructor
{
    class Rock
    {
        int a = 20, b = 60, c;

        public Rock()
        {
            c = a + b;
            Console.WriteLine(c);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Rock Rock1 = new Rock();
            Console.ReadKey();
        }
    }
}
Read Complete

what is constructor in c sharp with example


What is constructor in c#

Constructor is a special kind of method in c#. Constructor are create same as the class name. constructor never be return type, 

Every class created by default constructor. 

constructor can be parameterized. 

constructor can be overloaded.

We can create more then one constructor in a class. 

How many Types of Constructor:-

There are Five types of Constructor.

1.Default Constructor.
2. Parameterized constructor.
3.Private Constructor.
4.Static Constructor.
5.Copy Constructor.

Syntax of Constructor:-

Using System;
Class Rock
{
Public Rock()------------>This is the default constrator
{
/////------------------////////
}
}

Example of Constructor:-

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

namespace what_is_constructor
{
    class RockProgrammer
    {
        int a = 50, b = 30, c;

        public RockProgrammer()
        {
            c = a + b;
            Console.WriteLine(c);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            RockProgrammer Rock1 = new RockProgrammer();
            Console.ReadKey();
        }
    }
}

output:-

Why use Constructor:-

Constructor call automatically , If you want to create program in c# the program is call automatically,we don't need to call.

Example- Suppose that ,A website of Home Page automatically call ,by default call HOME page. We don't call . so this is the best example of constructor.   

Why does a constructor not return any value:-

Syntax :-   Public Rock()

CLR already define void method in Constructor . so we do not define void method in program . Constructor never be return. 
Read Complete

What is Jquery


What is jQuery-  jquery is just like library. it is not any language. we can insert update delete etc in ajax method  in jquery library. Jquery is light wait script. Jquery accept html controls. Jquery is client side script.


There are seven property use in jquery data insert:-

1. url:' ',

2.type:' ',

3.datatype:' ',

4.contentType: ' ',

5.data: " ",

6.success:

7.error:



Step1.  Download jquery file.

Step2. Copy jquery file past in project.

step3. Drop the jquery file in Header section.

How to insert record in jquery:-

Read Complete

What is Json

what is Json-


Json is just like data format .it is not language. Jquery use in Json. Jquery does not use data set and data table.

Json is JavaScript object notation.

Json is Light wait Data format.

Json install command is :- (Install-Package Newtonsoft.Json -Version 6.0.1) 

copy this command past in Library package manager then Enter 

what is Json install command:-

Install-Package Newtonsoft.Json -Version 6.0.1 (run this command)

how to install json.net in visual studio 2012

Read Complete

21 Sep 2017

What is class and object in c sharp with example


Object are just like reference pointer.

Object are the basic run-time entity in an object oriented programming language. 

c# in create the object with new operator.

Object is used to allocate the memory according to blueprint(Class).

Syntax:-

(Rock r = new Rock();)//Allocate the memory//


Example of Class and Object:-


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

namespace What_is_object_in_c_sharp
{
    class Program
    {
        int Empid;
        string Emp_Name;
        static void Main(string[] args)
        {
            Program P1 = new Program();
            P1.Empid = 100;
            P1.Emp_Name = "Rock Programmer";
            Console.WriteLine(P1.Empid);
            Console.WriteLine(P1.Emp_Name);
            Console.ReadKey();
        }
    }
}
output is:-



Read Complete

How to insert data into Mysql database using jquery ajax

How to insert record in database using Jquery:-

Create Table:-

create table Employee
(
Empid int primary key identity(1,1),
Name varchar(50),
Age int,
Address varchar(50)

)

Create insert Procedure:-

create proc usp_employee_insert
@Name varchar(50),
@Age int,
@Address varchar(50)
as
begin
insert into Employee(Name,Age,Address) values(@Name,@Age,@Address)
end

use to j query code with ado.net:-

j query in does not use server control only on html control. j query support Json. How to install json 

Aspx page code in j query:-

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Registration.aspx.cs" Inherits="Jqueryinsertonly.Registration" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            Getdata();
        });

        function Savedata()
        {
            $.ajax({
                url: 'Registration.aspx/Insert',
                type: 'post',
                contentType: 'application/json;charset=utf-8',
                datatype: 'json',
                data: "{A: '" + $("#textname").val() + "', B:'" + $("#textage").val() + "',C: '" + $("#textaddress").val() + "'}",
                success: function () {
                    alert('data is insert !!');
                    Getdata();
                },
                error: function () {
                    alert('data error !!');
               }
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>Nmae:</td>
                    <td><input type="text" id="textname" /></td>
                </tr>

                <tr>
                    <td>Age:</td>
                    <td><input type="text" id="textage" /></td>
                </tr>

                <tr>
                    <td>Address</td>
                    <td><input type="text" id="textaddress" /></td>
                </tr>

                <tr>
                    <td></td>
                    <td><input type="button" id="btnsave" value="Save" onclick="Savedata()" /> </td>
                </tr>

            </table>
        </div>
    </form>
</body>
</html>

CS page code of Jquery:-

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.Configuration;
using System.Web.Services;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;


namespace Jqueryinsertonly
{
    public partial class Registration : System.Web.UI.Page
    {
        static SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBC"].ConnectionString);
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [WebMethod]
        public static void Insert(string A, int B, string C)
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("usp_employee_insert", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@Name", A);
            cmd.Parameters.AddWithValue("@Age", B);
            cmd.Parameters.AddWithValue("@Address", C);
            cmd.ExecuteNonQuery();
            con.Close();
        }
    }

}


Web.config file code:-


<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>
<connectionStrings>
  <add name="DBC" connectionString="data source=Shiva; integrated security=true;initial catalog=jqueryinsertonly"/>
</connectionStrings>
</configuration>

Read Complete

What is partial class with example


Partial class is used to in single namespace. Partial class can't we declare in different namespace. Partial class used to multi pal source file in single namespace ,but it will be compiled only single one classs at run time

Example:-
Suppose that we have a class "Rock_Programmer" The "Rock_Programmer" class divided into source file  Rock_Programmer1"  and "Rock_Programmer2" but the compile 
the source code then create a single class.

Example of Partial class:-

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

namespace What_is_partial_class
{
    partial class Partial1
    {
        public void Rock1()
        {
            Console.WriteLine("Hello Rock Programmer");
        }
    }
    partial class Partial1
    {
        public void Rock2()
        {
            Console.WriteLine("I am Partial Class");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Partial1 obj = new Partial1();
            obj.Rock1();
            obj.Rock2();
            Console.ReadKey();
        }
    }
}

Output is:-


Read Complete

20 Sep 2017

what is static method With Example


Static method always call same as the class name.Static method does not depend any object.and Static method can be define in static class, but we can not define in non static class.

you can use access modifier before static mathod like as a Public,Private,etc.

Syntax of Static Method:-

Example of Static Method in C#:-

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

namespace What_is_static_method
{
    static class Program
    {
        public static void show()
        {
            Console.WriteLine("Hello Rock programmer");
        }
        class Dev
        {
            static void Main(string[] args)
            {
                Program.show();
                Console.ReadKey();
            }
        }
    }
}

Read Complete

what is static variable in C Sharp with example


Static variable does not create in non static class.

Static variable declare always global level and class level 
but we can't declare static variable on method level.

syntex:-

If you want to make the int B=15 static then out put is 11.

Static variable created by on time memory allocated but memory in will be value override.

As a before 11 then after override 12. 

Example of Static variable:-

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

namespace what_is_static_variable
{
   class Program
    {
        static int a = 10;
        public  void Show()
        {
             a++;
            Console.WriteLine(a);
        }
    }
    class Devesh
    {
       public static void Main(string[] args)
        {
            Program aa = new Program();
            aa.Show();
            Console.ReadKey();
        }
    }

}
Output:-

Read Complete

what is static class in c sharp with example


static is a keyword, Static class Does not create any type of Object and Static Class .

Static Class always call same as the class name.(static   method)

Static Class does not depend any object.

Static Class created by only Static Contractor.

(static Varibal)

Example of Static Class:-

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

namespace What_is_static_class
{
    static class Programmer
    {
        
        public static void show()
        {
            Console.WriteLine("Hello Rock Programmer");
        }
    }
    class Rock
    {
       public static void Main(string[] args)
        {
            Programmer.show();
            Console.ReadKey();
        }
    }

}

Output of:-





Read Complete

18 Sep 2017

What is Abstract class in C sharp


Abstract class is a keyword in an object oriented programming language and we never be create object in abstract class,


We can use abstract keyword before class and before method.

abstract method close with semicolon(;) ,

Syntax:-

 abstract class Program
    {

        public abstract void show();
        public void XYZ()
        {
            Console.WriteLine("I am Abstract class");
        }

    }

abstract method con not be use open close curly braces({--}),

abstract method use just like interface.

Example :-

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

namespace abstractclass
{
    abstract class Program
    {

        public abstract void show();
        public void XYZ()
        {
            Console.WriteLine("I am Abstract class");
        }
    }
    class ABC : Program
    {
        public override void show()
        {
            Console.WriteLine("Hello");
        }
        public void get()
        {
            Console.WriteLine("Hi");
        }
    }

}
Read Complete

Popular Posts

Popular Posts

Translate

Total Pageviews