Asp.net Disable postback LinkButton

Add fallowing code to your page_load HTML:

<asp:LinkButton ID="myLinkButton" runat="server" Text="Click Me"></asp:LinkButton>

Code:
protected void Page_Load(object sender, EventArgs e)
{
myLinkButton.Attributes.Add("onClick", "return false;");
}

Happy tips&tricks :)

32-bit flag struct example named BitFlagVector32

An example of Flag struct that using interger and set by bits

    public struct BitFlagVector32
    {
        private int data;
        public BitFlagVector32(int data)
        {
            this.data = data;
        }
        public int IntegerValue
        {
            get
            {
                return this.data;
            }
            set
            {
                this.data = value;
            }
        }
        public bool this[int bit]
        {
            get
            {
                return ((this.data & bit) == bit);
            }
            set
            {
                int data = this.data;
                if (value)
                {
                    this.data = data | bit;
                }
                else
                {
                    this.data = data & ~bit;
                }
            }
        }
 
 
        public void Set(int bit)
        {
            this.data |= bit;
        }
        public void Clear(int bit)
        {
            this.data &= ~bit;
 
        }
 
 
    }
 
    public static class UsageClass
    {
        public static BitFlagVector32 flag = new BitFlagVector32(15);
        public static void Usage()
        {
 
            flag.Clear(0x00);  //No effect
            flag.Clear(0x01);  //value 14  00001110
            flag.Clear(0x02);  //value 12  00001100  
            flag.Clear(0x04);  //value 8   00001000
            flag.Clear(0x08);  //value 0   00000000
 
            flag.Set(0);        //No effect
            flag.Set(0x01);  //value 0   00000001
            flag.Set(0x02);  //value 0   00000011
            flag.Set(0x04);  //value 0   00000111
            flag.Set(0x08);  //value 0   00001111
 
        }
    }
...

c# Ping with Simple Pinger Example

using System;
using System.Threading;
using System.Windows.Forms;
using System.Net.NetworkInformation;
 
 
namespace ContextHelper
{
    static class Pinger
    {
        public static void Ping(string url_or_IP)
        {
            using (Ping ping = new Ping())
            {
 
                try
                {
                    Console.Write("    {0}...", url_or_IP);
                    PingReply reply = ping.Send(url_or_IP, 100);
                    if (reply.Status == IPStatus.Success)
                    {
                        Console.WriteLine("Success - IP Address:{0}", reply.Address, reply.RoundtripTime);
                    }
                    else
                    {
                        Console.WriteLine(reply.Status);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error ({0})",
                        ex.InnerException.Message);
                }
 
            }
        }
    }
}

c# Single instance of an application on one machine

Some times you want one running instance for your application then you can deny another running instance with this code.

using System;
using System.Threading;
using System.Windows.Forms;
 
 
namespace MyApp
{
    static class Program
    {
        static Mutex _Mutex = null;
 
        [STAThread]
        static void Main()
        {
            bool myAppFirstInstance;
            _Mutex = new Mutex(true, "Global\\MyApp ", out myAppFirstInstance);
            if (myAppFirstInstance)
                Application.Run(new MainForm());
            else
                MessageBox.Show("There is already exists a running instance of this application",
                    "Warning",
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
        }
    }
}

c# Use As , not is in

In C#, use as, not is. The is keyword is used to see whether a reference can be cast as particular type, but it doesn’t return a reference converted to that type. So usually, if you get a positive result from the is, the first thing you’ll do is a cast—effectively implementing the same cast twice. With the as keyword, a reference cast as the new type is returned if it’s valid and a null is returned if it’s not. You then can check for the null and do what you like. The asapproach is fully 50% faster than the is approach.