Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Wednesday, August 31, 2011

Delegate-Lambda Expression (=>):

 

 

Lambda Expression  (=>):

 

A lambda expression is an unnamed method written in place of a delegate instance.

The compiler immediately converts the lambda expression to either

 

  • Delegate Instance
  • Unmanaged Method
  • Lambda Expression it introduced in C# 3.0

 

Below is delegate method declaration

 

     public delegate int AddTwoNumberDel(int fvalue, int svalue);

 

     We can use lambda expression

       

                 AddTwoNumberDel AT = (a, b) => a + b;

          int result=   AT(1,2);

          MessageBox.Show(result.ToString());

 

Before that what we used Please check this url

 

http://jsdotnetsupport.blogspot.com/2011/08/beginner-delegate-program.html

 

 

What is Syntax in Lambda Expression?:

 

A lambda expression has the following form:

 

(parameters) => expression-or-statement-block

 

(a, b) => a + b;   this program

 

(a, b)  èParameter

a+b     è Expression /statement block

=>      è  Lambda Expression

 

You can write Following format also

 

(a, b) =>{ return  a + b }

 

Func ,Action Keyword:

 

Lambda Expression mostly used Func and Action Keyword

  • Func Keyword is one of the generic Delegate

Example 1:

 

Func<int, int,string> Add = (fvalue, svalue) => (fvalue + svalue).ToString();

            MessageBox.Show(Add(3, 5));          // outPut 8

           

Example 2:

 

Func<int, int, int> Add = (fvalue, svalue) => fvalue + svalue;

            MessageBox.Show(Add(3, 5).ToString());          // outPut 8

 

Above program  how its working ?

 

Func  è Func is Keyword

 

Func<int, int,string> è first Two type is parameter ,Last type is return type

 

Add  è Add is Method Name

 

(fvalue, svalue èParameter

 

(fvalue + svalue).ToString(); è Statement

 

 

Other feature:

 

  • You can access outer variable also 

Ex:

 

Int value=50;

 

Func<int, int, int> Add = (fvalue, svalue) => fvalue + svalue+ value;

            MessageBox.Show(Add(3, 5).ToString());          // outPut 58

 

Question ?

 

Int value=50;

 

Func<int, int, int> Add = (fvalue, svalue) => fvalue + svalue+ value;

  

    Int value=100;

 

            MessageBox.Show(Add(3, 5).ToString());  

 

    Int value=200;

 

Post your Answers ….Get Special Gift ….  To Bloger…..

 

 

Action Keyword:

 

Action Type same like Func method but The Action type receives parameters but does not return a parameter. The Func type, however, receives parameters and also returns a result value. The difference is that an Action never returns anything, while the Func always returns something. An Action is a void-style method in the C# language

 

Example:

 

using System;
 
class Program
{
    static void Main()
    {
      // Example Action instances.
      // ... First example uses one parameter.
      // ... Second example uses two parameters.
      // ... Third example uses no parameter.
      // ... None have results.
      Action<int> example1 =
          (int x) => MessageBox.Show("Write {0}", x);
      Action<int, int> example2 =
          (x, y) => MessageBox.Show ("Write {0} and {1}", x, y);
      Action example3 =
          () => MessageBox.Show ("Done");
      // Call the anonymous methods.  Or example1(1)
      example1.Invoke(1);
      example2.Invoke(2, 3);
      example3.Invoke();
    }
}
 
 
 
Output
Write 1
Write 2 and 3
Done

Thursday, August 25, 2011

doubt...User Controls VS Custom Controls


Hi Ravi,
 

What are user controls?

  • User controls are custom,
  • reusable controls, 
  • Microsoft offer an easy way to partition and reuse common user interfaces across ASP.NET Web applications
How to create User Control,
 
Ctrl+Shift +A  => Add Usercontrol ==> Design control
 
Rules For creating user controls:
 
The syntax you use to create a user control is similar to the syntax you use to create a Web Forms page (.aspx).
The only difference is that a user control does not include the <html>, <body>, and <form> elements since a Web Forms page hosts the user control.
 
How to Add your User Control;
 
you can register your control in particular  your page
<%@ Register TagPrefix="UC" TagName="TestControl" Src="test.ascx" %>
and add control
<html>     <body>           <form runat="server">                <UC:TestControl id="Test1" runat="server"/>           </form>     </body>   </html> 
How to add RunTime:
 
// Load the control by calling LoadControl on the page class. Control c1 = LoadControl("test.ascx");              // Add the loaded control in the page controls collection.	 Page.Controls.Add(c1); 
 

What are custom controls?

 

Custom controls are compiled code components that execute on the server,
expose the object model, 
and render markup text,
such as HTML or XML, as a normal Web Form or user control does.
 
How to create Custom control:
 
Ctrl+Shift+A=> Add class library=>render control => excute program
 
User Control vs Custom Control:
 
 
 
 

Factors

User control

Custom control

Deployment

Designed for single-application scenarios

Deployed in the source form (.ascx) along with the source code of the application

If the same control needs to be used in more than one application, it introduces redundancy and maintenance problems

Designed so that it can be used by more than one application

Deployed either in the application's Bin directory or in the global assembly cache

Distributed easily and without problems associated with redundancy and maintenance

Creation

Creation is similar to the way Web Forms pages are created; well-suited for rapid application development (RAD)

Writing involves lots of code because there is no designer support

Content

A much better choice when you need static content within a fixed layout, for example, when you make headers and footers

More suited for when an application requires dynamic content to be displayed; can be reused across an application, for example, for a data bound table control with dynamic rows

Design

Writing doesn't require much application designing because they are authored at design time and mostly contain static data

Writing from scratch requires a good understanding of the control's life cycle and the order in which events execute, which is normally taken care of in user controls

 
 
Reference :
 
Micrsoft
 
Thanks to Micrsoft 
  
On Thu, Aug 25, 2011 at 3:37 PM, ravi kumar <ravidravi@gmail.com> wrote:
  
What is the Difference between user control & custom control in asp.net.....Please give me some example......
 

Wednesday, August 24, 2011

Runtime Assign Method using Delegate


Writing Plug-in Methods with Delegates




A delegate variable is assigned a method dynamically. This is useful for writing plug-
in methods. In this example, we have a utility method named  Add,Sub that applies
a NumberOper . The NumberOper method has a delegate
parameter,


   ///

        /// delegate  declaration
        ///

        ///
        ///
        ///
        public delegate int NumberOperation(int fvalue, int svalue);
        ///

        /// Button click event it will call NumberOper method
        ///

        ///
        ///
        private void btnClick_Click(object sender, EventArgs e)
        {
            int a = Convert.ToInt16(txtfvalue.Text);
            int b = Convert.ToInt16(txtsvalue.Text);
            txtresult.Text = NumberOper(a, b, Add).ToString();//Dynamic we Assign Method name
        }
        ///

        /// Button click event it will call NumberOper method
        ///

        ///
        ///
        private void btnSub_Click(object sender, EventArgs e)
        {

            int a = Convert.ToInt16(txtfvalue.Text);
            int b = Convert.ToInt16(txtsvalue.Text);
            txtresult.Text = NumberOper(a, b, Sub).ToString(); //Dynamic we Assign Method name

        }

        ///

        /// Main Method with delegate Parameter
        ///

        /// first value
        /// second value
        /// Dynamic Delegate
        /// call method add or sub and return result
        public int NumberOper(int a, int b, NumberOperation AT)
        {

          return   AT(a, b);
        }

        ///

        /// Add two numbers Methos
        ///

        /// first Value
        /// Second value
        /// Result
        public int Add(int a, int b)
        {
            return a + b;
        }
        ///

        /// Sub two number
        ///

        /// first value
        /// Second value
        /// int value
        public int Sub(int a, int b)
        {
            return a - b;
        }



Beginner Delegate program

Add Two Number Delegate Program 

 public delegate int AddTwoNumberDel(int fvalue, int svalue);

        private void btnClick_Click(object sender, EventArgs e)
        {
            AddTwoNumberDel AT = Addnumber;                   // create delegate instance
           //is shorthand for

            //AddTwoNumberDel AT = new AddTwoNumberDel(Addnumber);

           
            int a = Convert.ToInt16(txtfvalue.Text);
            int b = Convert.ToInt16(txtsvalue.Text);
            txtresult.Text = AT(a, b).ToString();          // invoke Method
            //is shorthand for
            //txtresult.Text = AT.Invoke(a, b).ToString();
        }


        public int Addnumber(int fvalue, int svalue)
        {

            return fvalue + svalue;

        }
Note:
Copy and past your VS Editor it will Work... Do you want sample application mail me ...

C# Dotnet Delegate

What is Delegate?

 

·         Its reference to method.

·         once method assign to delegate its work like method

·         delegate method used any other method

 

 Where we will use real time?

 

      If you want to call Function in Runtime .and to get data after you can call your function but method name you don't  know design time  but you know runtime during time  you can use "Delegate"

 

Different type of Delegate:

 

  • Single cast Delegate
  • Multicast Delegate

 

 

Single cast Delegate Syntax:

 

  Below are signature of single cast delegate

 Access-modifier delegate result-type identifier ([parameters]);

Access-modifier è Its Access permission for delegate (like public ,private ..,)

Delegate      è it's a Keyword

Result-type èthis is  return type (like int,string,void)

Identifier è delegate name (user define)

Parameter è run time value passing

 

Ex :

 

Way 1:

 

public delegate void  jsdelegate();

 

above example is no return type ,no parameter

 

Way 2:

 

public delegate string   jsdelegatevalue(int x,int y);

 

above example is string is return type and x,y is parameter

 

above 2 way  are delegate  declaration

 

What is Advantage in VS 2010 Editor?

What is Advantage in VS 2010 Editor?

 

·          There is now support for multiple monitors and the ability to drag windows outside the IDE

·          IntelliSense is now two to five times quicker than previous versions.

  •   Readability of text is improved.
  • Add reference is previously very slow .now is very fast
  • Intelligence now support partial string matching   if you are type SB it will match string StringBuilder also

ExampleJSVS2010.png

Tuesday, August 23, 2011

WCF Programming Model

Disadvatage:

  1. Disadvantage is that only HTTP protocol could be used.
  2. Another disadvantage is all the service will run on the same port.

WCF Programming Model:

WCF service have three parts  .Service,End Point,Hosting

Service  it is a class written in a .net language which have some method.service have one or more endpoint

Endpoint means communicate with client.end point have 3 parts  'ABC':

·         'A' for Address,

·         'B' for Binding

·         'C' for Contracts.

Address(WHERE): Address specifies the info about where to find the service.

Binding(HOW): Binding specifies the info for how to interact with the service.

Contracts(What): Contracts specifies the info for how the service is implemented and what it offers.

 

 

Monday, August 22, 2011

What is WCF ?

WCF

 

·         Windows Communication Foundation  is a programming platform and runtime system for building, configuring and deploying network-distributed services.

·         It is the latest service oriented technology.

·         WCF is a combined features of Web Service, Remoting, MSMQ and COM

WCF Advantaged:

  1. WCF is interoperable with other services when compared to .Net Remoting,where the client and service have to be .Net.
  2. WCF services provide better reliability and security in compared to ASMX web services.
  3. In WCF, there is no need to make much change in code for implementing the security model and changing the binding. Small changes in the configuration will make your requirements.
  4. WCF has integrated logging mechanism, changing the configuration file settings will provide this functionality.

5.      WCF services can be debugged now in Visual Studio 2008 /2010. Wcfsvchost.exe will do it for you because service will be self hosted when you start debugging.

WCF vs WebService:

Wcf and Webservice have some difference  

Features

Web Service

WCF

Hosting

It can be hosted in IIS

It can be hosted in IIS, windows activation service, Self-hosting, Windows service

Programming

[WebService] attribute has to be added to the class

[ServiceContraact] attribute has to be added to the class

Model

[WebMethod] attribute represents the method exposed to client

[OperationContract] attribute represents the method exposed to client

Operation

One-way, Request- Response are the different operations supported in web service

One-Way, Request-Response, Duplex are different type of operations supported in WCF

XML

System.Xml.serialization name space is used for serialization

System.Runtime.Serialization namespace is used for serialization

Encoding

XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom

XML 1.0, MTOM, Binary, Custom

Transports

Can be accessed through HTTP, TCP, Custom

Can be accessed through HTTP, TCP, Named pipes, MSMQ,P2P, Custom

Protocols

Security

Security, Reliable messaging, Transactions