Wednesday 21 November 2018

What is delegates in c#?

C# delegates are similar to pointers to functions, in C or C++. A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime.

Delegates are especially used for implementing events and the call-back methods. All delegates are implicitly derived from the System.Delegate class.

A delegate can be declared using delegate keyword followed by a function signature as shown below.

<access modifier> delegate < return type> <delegate_name>(<parameters>)

The following example declares a Print delegate. 

public delegate void Print(int value)
 

Instantiating Delegates

Once a delegate type is declared, a delegate object must be created with the new keyword and be associated with a particular method. When creating a delegate, the argument passed to the new expression is written similar to a method call, but without the arguments to the method.

Example:

class Program
{
    // declare delegate
    public delegate void Print(int value);

    static void Main(string[] args)
    {
        // Print delegate points to PrintNumber
        Print printDel = PrintNumber;
          
        printDel(100000);
        printDel(200);

        // Print delegate points to PrintMoney
        printDel = PrintMoney;

        printDel(10000);
        printDel(200);
    }

    public static void PrintNumber(int num)
    {
        Console.WriteLine("Number: {0,-12:N0}",num);
    }

    public static void PrintMoney(int money)
    {
        Console.WriteLine("Money: {0:C}", money);
    }
}
 

Output:

Number: 10,000 
Number: 200 
Money: $ 10,000.00 
Money: $ 200.00
    Here, we have declared Print delegate that accepts int type parameter and returns void. In the Main() method, a variable of Print type is declared and assigned a PrintNumber method name. Now, invoking Print delegate will in-turn invoke PrintNumber method. In the same way, if the Print delegate variable is assigned to the PrintMoney method, then it will invoke the PrintMoney method.

Friday 21 November 2014

Firefox dumps Google for search, signs on with Yahoo


Google's 10-year run as Firefox's default search engine in the US is over. Yahoo wants more search traffic, and a deal with Mozilla will bring it.

Now users can search the web in 1997 with a browser from 2014. :)

The change will come to Firefox users in the US in December, and later Yahoo will bring that new "clean, modern and immersive search experience" to all Yahoo search users. In another part of the deal, Yahoo will support the Do Not Track technology for Firefox users, meaning that it will respect users' preferences not to be tracked for advertising purposes.


Mozilla has been working with Yahoo for months on the partnership, and relations with Yahoo's new CEO have been good, Baker said.

Tuesday 4 November 2014

Checked Change event of tree view is not working

I had an answer in the stackoverflow.com site over here:  http://stackoverflow.com/a/26134415/1042848

Allow only decimal numbers in the Textbox using Javascript

Javascript code:

    <script language="Javascript" type="text/javascript">
        function onlyNos(e, t) {
            try {
                if (window.event) {
                    var charCode = window.event.keyCode;
                }
                else if (e) {
                    var charCode = e.which;
                }
                else { return true; }
                if (charCode > 31 && (charCode < 48 || charCode > 57)) {
                    if (charCode === 46)
                        return true;
                    else
                        return false;
                }
                return true;
            }
            catch (err) {
                alert(err.Description);
            }
        }
    </script>

Textbox:

<asp:TextBox ID="txtNumbersOnly" runat="server" onkeypress="return onlyNos(event,this);" Width="146px" CssClass="rightinput"></asp:TextBox> 

Friday 28 March 2014

ASP.NET Page Life Cycle

When an ASP.NET page runs, the page goes through a life cycle in which it performs a series of processing steps. These include initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering. It is important for you to understand the page life cycle so that you can write code at the appropriate life-cycle stage for the effect you intend.

You can go through the entire life cycle in details at: ASP.NET Page Life Cycle Overview


Saturday 1 March 2014

What is Managed Code?

Managed code run under the control of CLR. So CLR execute this managed code.

All IL codes are managed code hence it is run under the control of CLR. And if have used any component which is not built on .NET framework then such referenced codes are called unmanaged code.

What is Common Language Runtime (CLR) in .NET?

Common Language Runtime or CLR is responsible for executing your application code and the code running under the control of CLR is also called managed code.

Any application written in any language of .Net framework will never directly compiled to machine understood code instead the compiler converts the code into a special language called MSIL (Microsoft Intermediate Language) and then CLR compile MSIL into platform-specific code.
So only the methods that are actually called during execution are compiled.

So in short, the .NET Framework understands only one language that is MSIL.