Sunday, 28 October 2012

What is Delegates ? Explanation with simple example.


      This is the most powerful  and exciting new feature of c# or c sharp. This concept , the core of object oriented programming , allows you to worry more about the flow of the system at lowest level, without worrying about the specifics of individual tasks that will be handled.
    What does delegate means? In UK,USA  ,people elect their  delegates to represent their legislature or council. These Delegates represent the entire nation or state because it is impossible if the entire populations were to present to represent countries. In short ,you can say delegates is like as  function pointer  in c or c++.

What is Function pointer?
Function pointer is pointer .i.e variable , which point to the address to the function.
In other word we define delegates  “ it allows us to reference of method.”
Types Of Delegates:
There are two types of delegates:-
1.)Single cast delegates
2.)Multiple cast delegates

Syntax of Delegate:
1.)Single cast delegates:
public  Delegate <return  type>   <delegate_name>(parameters)
2.)Multiple cast delegates:
public Delegate void  <delegate_name >(parameters)

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

namespace Delegate
{
    public delegate int Delg(int x,int y);
    public class Math
    {
        public static int Add(int x,int y)
        {
            return x + y;
        }
        public static int Mul(int x,int y)
        {
            return x * y;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Delg  del = new Delg(Math.Add );
            int add = del(7,7);
            Console.WriteLine(add);
            Delg del1 = new Delg(Math .Mul );
            int mul1 = del1(5,6);
            Console.WriteLine(mul1);
            Console.ReadLine();
        }
    }
}


Advantages of Delegates:
Dynamic binding can be done by using delegate because we can call more than one method at a time dynamically by calling the delegate in which method is defined.
Static delegate is used for delegate  without  creating a local delegate instant. Just pass in the static delegate of class.
Disadvantage of delegate:
The problem with static delegate that it must be instantiated whether they are in use or not.

Friday, 26 October 2012

What is the difference between for and foreach loop?

foreach loop or statement is same as for loop or statement with a slight difference.In foreach loop , loop irterate through array and collections. Unlike for loop, foreach loop does not have test condition means it does not check any condition.
Example:

foreach Loop:

foreach( data_type data_variable in collection_name)
{
// your code
}

for loop:

for(data_type variable ;condition;update )
{
// your code
}

How to open computer without password?

Hi Friend's , Here I have explained some computer tips and tricks.
 If  you want to open your or someone else then it is too simple to open computer without password.
For this you have just do one simple step.
At login type administrator in user name  and click on login . This will open your computer without password.
If you don't believe just try it. If it will work just give a comment.

How to download Sql Server 2012.

Hi friend's , You can download sql server 2012 from the micrsoft site . If you want to crack it then You have    to do just one thing means just send a mail and i will send you cracker of server 2012. If you want to download sql server 2012 click here.

Tuesday, 23 October 2012

what are the core security feature of WCF address?


There are four core security feature of WCF
1.)Confidentiality: It is ensure that information doesn't go in wrong hand when it travels from sender to receiver.
2.)Integrity: It ensure that the receiver get the same  information that sender sends without any change in data.
3.)Authentication: It verifies who is the sender and who is receiver.
4.)Authorization: It verifies that the user is authorized or not for performing the action they are requesting from the application.


What are the main components of WCF.

Hi friend's, Here I have explained the main components of WCF.

There are three main components of WCF
1.)Service Class
2.)Hosting Environment
3.)End Point

what are the various ways of hosting of WCF?

Hi Friend's ,Here I have explained the various ways of hosting of WCF.

There are three ways to host WCF services:-
1.)Self Hosting:-Hosting the service on own machine or application domain.
2.)IIS Hosting:- Hosting the services on IIS server. Host the application on IIS server or provided by IIS server.
3.)WAS Hosting:- Hosting the applicarion on Windows Active Service (WAS) server.

Thursday, 18 October 2012

Factorial using recursion in c sharp

Hi Friend's ,Here I have Written code for Factorial using recursion in c#.

code:

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

namespace FactorialUsingRecursion
{
    class Program
    {
        static void Main(string[] args)
        {
           
            Console.WriteLine("Enter number.........");
            int n = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(Factorial(n));
            Console.Read();
        }
        static long Factorial(int number)
        {
                        if (number < 1)
                return 1;
            else
                return number * Factorial(number - 1);
        }
    }
}

Factorial using for loop or without recursion in c sharp

Hi Friend's, Here I have written Factorial program without using recursion.

Code:

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

namespace Factorial
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter the number.....");
            Console.WriteLine(Factorial());
            Console.Read();
        }
        static long Factorial()
        {
            int n =Convert.ToInt32( Console.ReadLine());
            long Finalnumber = 1;
            for (int i = 1; i <= n;i++ )
            {
                Finalnumber = Finalnumber * i;
            }
            return Finalnumber;
          
        }
    }
}

Count the number of vowels in string using c#.

Hi Friends, Here I have Written a simple program to count no of vowels in string in c sharp.

Code:

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

namespace FindVowel
{
    class Program
    {
        static void Main(string[] args)
        {
            int my_count = 0;
            Console.WriteLine("Enter String........");
            string myString= Console.ReadLine();
            foreach(char ch_vowel in myString)
            {
                switch (ch_vowel)
                {
                    case 'a':
                    case 'A':
                        my_count++;
                        break;
                    case 'e':
                    case 'E':
                        my_count++;
                        break;
                    case 'i':
                    case 'I':
                        my_count++;
                        break;
                    case 'o':
                    case 'O':
                        my_count++;
                        break;
                    case 'u':
                    case 'U':
                        my_count++;
                        break;
                }
            }
            Console.WriteLine("Number of vowels are :{0}",my_count);
            Console.Read();
        }
    }
}

Fibbonacci series program using recursion in C#.

Hi Friends, Here I have Written Fibbonacci series code in C sharp.

Code:

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

namespace Fibbonacies
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i <= 10;i++ )
                Console.WriteLine(Fibbonanci(i));
            Console.Read();
        }
        static int Fibbonanci(int x)
        {
            if (x < 1)
                return 1;
            return Fibbonanci(x - 1) + Fibbonanci(x-2);
        }
    }
}

Sunday, 14 October 2012

What is url routing?


Hi Friend’s ,Here I have explained a new feature in asp.net 4.0.

Introduction:

URL routing is one of the new thing in Asp.net4.0.You can just said that you can reduce the url length and make it user friendly i.e you can arrange the url in your own way. Developers  build the url dynamism , readability and flexibility to the user. You have seen lot of url’s that are very lengthy and ugly. User’s avoid to cut and paste or to remember it. It is very tuff task for user ‘s that means it is not user friendly.
You have seen url’s like
We know how ugly they are. To avoid such type of url name ,Asp.net 4.0 brings a new concept called url routing.
With the use of url routing  ,you can manage your url in proper way so that it is easy for cut and paste or user can remember the url.
After Using of url routing the url will become as below
Procedure for url Routing:
First you create a simple web project in which at least two web form.
Add  Global.asax file in this project.
Open Global.asax file  and write the code in following section:-
<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
       
        System.Web.Routing.RouteTable.Routes.MapPageRoute("",
    "Home",
    "~/linq/Default.aspx"); // in this code ~/linq/Default.aspx is the original name(url) and Home is the new name (It is written by myself or you can give the name  whatever you want )

    }
  
    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown

    }
       
    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends.
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer
        // or SQLServer, the event is not raised.

    }
      
</script>

 This is the simple url routing .
If you want to write the code on button event or any other event. For this you have to write the new name in Respose.Redirect(). Method.
For Example:
protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Home");
    }

Hope this will help u. If any query regarding this please Conatact me at sushilct86@gmail.com.
If you like this post do not forget to cooment.

Friday, 12 October 2012

How Linq is more benifacial than stored procedure?

Hi Friends , Here I have explained how linq is more benifacial than stored procedure.

There are three basic points that explain how linq is benifacial than stored procedure.
1.)  Debugging: It is very hard to debugg stored procedure but as we know linq is the part of .NET , so we can use debugger to debugg the linq query.
2.)Development: at the time of deployment , we use additional script for stored procedure but for Linq query it is complied into a single DLL hence deployment is easy.
3.)Type Safety: Linq is type safe , so queries error are type checked at complie time but in case of stored procedure error are checked at run time.

What is Linq in Asp.Net?

Hi Friends , Here I have explained about new topic .i.e Linq.

 Intoduction: 

Linq stands for Langauge Integrated Query.It the new feature of Asp.Net Starting in .NET 3.5. Linq is collection of  standard query operator that provides the query facilities in .NET framework langauge like c#,VB.NET.
:-It use a single syntax  for querying multiple data source such as sql server, MSAcesses, Oracle,XML data.
:- It is type safe and strongly type.
:- linq is that is programming langauge synatx that is used for querying data. 

What is web.config file in Asp.Net?


Hi friends , Here I have explained what is web.config file in Asp.Net.

Introduction:

Web.config is the central part of the  Asp.Net application. It is used to store the information to be accessed by web page. This  information  could be connectionString stored at at Centralized part so that it can be accessed in data driven page. If the connection string change its  just a matter of changing it at one place.
In the sample  we shall red the information from web.config using Asp.Net .
Below  the code have given as:-
Web.config:
<?xml version=”1.0” encoding=”utf-8”?>
<configuration>
<connectionString>
<add key=”connectionName”  connectionString=”Data Source=DataServerName; Initial Caalog= yourDatabaseName; Integrated Security=True”
</connectionString>
</configuration>
In Asp.Net
String  connStr=ConfigurtionManager.ConnectionString[“connectionName”].ConnectionString;
Sqlconnection  conSql=new SqlConnection(connStr);
consql.Open();
………write your code
conSql.Close();

Thursday, 11 October 2012

Differences between Abstract class and Interface.

Hi friends, Here I have explained what are the basic differences between Abstract class and Interface. This is the general question always asked in interviews.

There are  5 main differences between abstract class and Interface:-
1.)A class can implement many number of interfaces but a sub class can at most use only one abstract class.
2.) An abstract class can have non-abstract method(Concrete method) while in case of interface all the methods has to abstract.
3.)An abstract class can declare or use any variables while an interface is not allowed to do so.
          So the following code cann't be compiled:-
     interface TestInterface
{
int x=4;
int k=3;
void getMethod();
string getName();
}

abstract class TestAbstract
{
int i=4;
int x=3;
public abstract void getClassName();
}

It will generate a compile time error as:-
Error1 Interface cannot contain fields.

4.)An abstract class have constructor declaration while an interface can not do so.


  interface TestInterface
{
//constructor declaration
public TestInterface()
{

}
void getMethod();
string getName();
}

abstract class TestAbstract
{
public TestAbstract()
{

}
int i=4;
int x=3;
public abstract void getClassName();
}

Above code generate a compile time error as:-
Error1 Interface does not contain constructors.

5.) An abstract class is allowed to have all modifier for all of its member declaration while in interface we cannot declare any access modifier(including public) as all the member of interface are implicitly public.

Correct code:
public Interface TestInterface
{
void getMethod();
string getName();
}

Inccorect Code:

 Interface TestInterface
{
public void getMethod();
public string getName();
}

Monday, 8 October 2012

what is proxy in WCF? How to create proxy in WCF.

Hi Friends, Here i have explained what is proxy in WCF and How we create proxy in WCF.

Introduction:

The proxy is a CLR class that exposes a single CLR interface represnting the  service contract. The proxy provides the same operations as service contract. It also has additional method for managing the proxy life cycle and the connection to the service.The proxy completely encapsulate every aspect of the service:its location,  its implementation technology and runtime plateform , and the communication transport.

The proxy can be generated using Visual Studio by right clicking reference and clicking on add Service Refernce. This brings up the Add Service Refernce dialog box,Where you need to supply the base address of the service(or a base address and a MEX URI) and the namespace to contain the proxy.

Proxy can also be generated by using svcUtil.exe command line utility.We need to provide svcUtil with the HTTP-GET address or the metadata exchange endpoint address and ,optionally with a proxy filename. The default proxy filename is output.cs but you can also use the /out switch to indiacte a different name.


Tuesday, 2 October 2012

what is endpoint in WCF?



Hi friends,here i have explained a tiny question that was asked to my friend in interview.

Every service must have Address that defines where the service resides, Contract that defines what the service does and a Binding that defines how to communicate with the service. In WCF the relationship between Address, Contract and Binding is called Endpoint.

The Endpoint is the fusion of Address , Contract and Binding.

What is queryString in asp.net.


Hi friend, here i have explained about QueryString.
Introduction:
QueryString  is used to pass the variables content  between your HTML  page or aspx webform  context in asp.net. For Example if you collect the information like  user_name and id and you want to pass these value to another page.For this you can use QueryString.
Exmple :
 you want to show like this
http:/www.yourdomainname.com/default.aspx?username=Rahul&id=10023
for this you can write the code given below:

private void btnGO_Click(object sender, System.EventArgs e)
{
Response.Redirect(“Default.aspx?username=”+txt_username.Text+”&id=”+txt_id.Text);
}     

If you want  to retrieve these value  to another page write the code given below

private void Page_Load(object sender,System.EventArgs e)
{
txt_name.Text=Request.QueryString["username"];
Txt_id.Text=Request.QueryString["id"];
}

Advantage:

It is easy to write.

Limitations:
1.)It have a max length.If you have to send a lot information this approach doesn’t work.
2.)It is visible in your address part of your browser so you cant use it with the sensitive information.
3.)It can not be used to send & and space.

Wednesday, 26 September 2012

What are differences between system.stringbuilder and system.string?


1.)system.string is immutable but system.stringBuilder is mutable.
Immutable means once we created we cannot modified.    Suppose we want give new value to old value simply it discarded the old value and it will create new instance in memory to hold the new value.
2.)append keyword is used in string builder but not in system.string.

What is difference between Array list and hash table?


1.)Hash table store data as a name ,value pair while in array only value is store.
2.)To access value from Hash table ,you hve to pass name while in array ,to access value, you have to pass index number.
3.)You can store different data type in Hash table like int, string but in array you can store only similar type of data.

What are differences between Abstract and Interface?

Hi friends ,here i have explained "What are differences between Abstract and Interface".


Abstract Class:
->abstract  class provides a set of rules to implement next class.
->Abstract method does not contain any definition.
->In abstract all method are default.
->If a class contains at least one abstract method then it must be declared as an “Abstract class”.
->Abstract  classes cannot be instantiated i.e we cannot create object, but reference  can be created.
->If  a class contains all functions without  body then it is called as “Fully Abstract Class” .i.e Interface.

Interface:
->If a class contain all abstract methods then that class is known as “Interface”.
->Interface support multiple inheritance.
->In interface all method are public  by default.
->Interfaces are implementable.
->Interfaces cannot be instantiated , but a reference can be created.

What is the difference between stored procedure and function?



Hi friend , here i have explained "What  is the difference between stored procedure and function "
1.)Stored procedure can return  zero or more  means 0 or n values where as function can return only one value which is mandatory.
2.) Stored procedure have input , output parameters for it  whereas function can have only input parameters.
3.)Stored procedure allows to select as well as DML statement in it whereas function allows only select statement in it.
4.)Stored procedure can called a function whereas function can not called a stored procedure.
5.) Exception can be handled by try –catch block in a stored procedure but try-catch  block cannot be used in a function.
6.)We can go for transaction management in stored procedure but we cannot go in function.

What is an application object?



Hi friend , here i have explained about Application object.

Introduction:

Application object is used to store the information and access variables from any page in the application. Application object is same as the Session  object but only difference is that session object is used only for particular user.Apllication object  is same for all users once application object is created that application is used through out  all the pages in application (like database connection) and we change the application object  one  place those will changes in all the pages.
You can create the application object in Global.asax file and access those variable in all the pages. 
Add  the following code in Global.asax file :
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["UserID"] = "SureshDasari";
}
</script>
After this write the following code in aspx page:
<html> 
<head> 
<title>Application Object Sample</title> 
</head> 
<body> 
<form id="form1" runat="server"> 
<asp:Label id="lblText" runat="server"></asp:Label> 
</form> 
</body> 
</html> 

After that write the following code in .cs file:
public void Page_Load(object sender, EventArgs e)
{
this.lblText.Text =  "UserName: " + Application["UserID"] + "<br>";
}

Tuesday, 25 September 2012

What are the difference between ExecuteNonQuery , ExecuteReader and ExecuteScaler in ADO.NET

Hi friend,in this article i have explained what is the basic deifference between  ExecuteNonQuery , ExecuteReader and ExecuteScaler in ADO.NET.

ExecuteNonQuery:

ExecuteNonQuery method will return number of rows effected by INSERT,DELETEor UPDATE operations.ExecuteNonQuery method will be used only for insert,update,delete,and set staements;

ExecuteScaler :

ExecuteScalar method will return single row single column value i.e single value, on execution of sql query or stored procedure using command object.It is very fast to retrieve single values from database.

ExecuteReader :

ExecuteReader will be used to return the set of rows on execution of sql query or stored procedure using command object.This is used only forward retrieval of records and it is used to the table value from the first to last.

What is stored procedure ? What are the advantages using stored procedure in sql server

Hi friend, here i have explained about store procedure in sql server.

What is stored procedure:

Stored procedure is a group of sql statements that has been created and stored in the database.It is a pre-compiled sql query.It will accept input parameters so that a procedure can be used over the network by several clients using different input data. It reduce network traffic and increase the performence. if we modify the stored procedure all the clients will get the updated stored procedure.

sample of creating stored procedure:

create procedure procedure_name
(
@column_name1 datatype,
@column_name2 datatype,
@column_name3 datatype,
@column_name4 datatype
)
as begin
select * from table_name;
end;

Advantages of stored procedure:

1)stored procedure allows moduler programming.
You can create the procedure once,store in the database ,and call it many number of time in your program.

2)stored procedure allows faster execution.
  because it is precompiled sql query.

3)It reduces the network traffic.

4)Stored procedure provide the better security to your data.

There are three types of stored procedure:
a)system  stored procedure
b)user defined stored procedure
c)Extened stored procdure

How to find highest salary from different department

Hi friends,In this article i have explained how to find max salary from different department.
First create a table in database .
Enter some data in the table with different department .
Example:

create table m_salary(empid varchar(50),empname varchar(50),salary varchar(50),deptid varchar(50))
Enter some values in the table.

Sql query :

select deptid , MAX(salary) as sal  from m_salary  group by deptid ;

Run this query and I hope this will help you.

Difference between char,varchar and nvarchar in sql server

Hi friends,In this article i have explained what is the difference between char , varchar and  nvarchar in sql server.

char Data Type:

char datatype is used to store fixed length of character.For example if we declared char(50) it will allocate memory for character 50. once we declare char(50) and insert only 10 character then it only use 10 character of memory and other 40 character of memory will be wasted.

varchar datatype:

Varchar means variable character .It will allocate the memory based on number of character inserted. Suppose that if we have declare varchar(50) it allocate 0 memory of character  at the time of declaration.
Once we declare varchar(50) and insert only 10 values the it only use 10 character of memory.

nvarchar datatype:

nvarchar datatype same as varchar datatype but only difference nvarchar is used to store unicode characters and  it allows to store multiple lagauges in database.
 

Tuesday, 18 September 2012

Arrange the string in ascending and descending order

Hi Friend, I hope you have enjoyed from my previous article .i.e When user enter numeric value ,print out the character values.
Here i will explain how to arrange string in ascending and descending order.
First open visual studio > open new project> click on console application > give the name of the application> click ok.

Code:

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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//user to enter list of username
Console.WriteLine("please enter the name seperated by comma");
//read the user name from console
string username = Console.ReadLine();
// split the string into string array by comma
string[] arrusername = username.Split(',');
// print the name before sorting
Console.WriteLine("Name before sorting");
foreach(string userName in arrusername)
{
Console.WriteLine(userName);
}
// sort the element in ascending order
Array.Sort(arrusername);
// print the element after sorting
Console.WriteLine("string after sorting");
foreach(string userName in arrusername)
{
Console.WriteLine(userName);
}
// sort the element for descending order
Console.WriteLine("-------------------for Descending order");
Array.Reverse(arrusername);
// print the element in descending order
foreach(string userName in arrusername)
{
Console.WriteLine(userName);
}
Console.ReadLine();
}
}
}

I hope you will enjoy with this code.

When user enter numeric value ,print out the character values

Hi friend , this question is generally asked from freshers and sometime from experianced professionals.

The question is when user enter numeric value then it print character value .
Here i have explained how to overcome from this problem.
First open a console application in visual studio and give it some name.

Code:

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

namespace printcharacter
{
class Program
{
static void Main(string[] args)
{
  Console.WriteLine("please enter  numeric value");
int str = Convert.ToInt32(Console.ReadLine());
Console.WriteLine((char)(str + 64));

Console.ReadLine();
}
}
}

I hope You will enjoy .