5 September 2013

Access Modifiers in c#

Access Modifiers in c#

public
The type or member can be accessed by any other code in the same assembly or another assembly that references it.
private
The type or member can be accessed only by code in the same class or struct.
protected
The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.
internal
The type or member can be accessed by any code in the same assembly, but not from another assembly.
protected internal
The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.


Extension Methods in C#

Extension Methods in C#

Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type.

Remove $ from the string using Extension Methods in C#

using System;
using System.Windows.Forms;

namespace ExtensionMethodsExample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ExtensionMethodExample();
        }


        private void ExtensionMethodExample()
        {
            string dollarval = "2000$";

            dollarval = dollarval.RemoveDollarSign();
        }
    }


    public static class RemoveDollar
    {
        public static String RemoveDollarSign(this string dollarval)
        {
            string val = dollarval.Replace("$", "");
            return val;
        }

    }

}




Consistency level in Azure cosmos db

 Consistency level in Azure cosmos db Azure Cosmos DB offers five well-defined consistency levels to provide developers with the flexibility...