11 July 2012

String vs string in c#

String vs string in C#

we use either the keyword string or  String .

Is both String and string same in C# ?

string is just an alias name for the class System.String which means both has the same functionality.
The IL code generated for both of them is also same .
Note that string is a keyword , but String isn’t which lets you create an variable with the name String like


Another interesting thing is we can also declare variable name as String

 String String = "Arun Prakash";
 MessageBox.Show(String);


 If you declare the variable name as string, Error occured

 String string = " Arun Prakash";
 MessageBox.Show(string);







Use of Using Statement in C#


Use of Using Statement in C#

In C#, using Keyword is used in two different ways and are hence referred to differently.
 As a Directive
In this usage, the "using" keyword can be used to include a namespace in your program. (Mostly used)
As a Statement
Using can also be used in a block of code to dispose an IDisposable objects.

SqlConnection connection = new SqlConnection("connection string");
SqlCommand cmd = new SqlCommand("SELECT * FROM SomeTable", connection);
SqlDataReader reader = cmd.ExecuteReader();
connection.Open();
if (reader != null)
{
      while (reader.Read())
           {
                          //do something
           }
}
reader.Close(); // close the reader
connection.Close(); // close the connection

  
Disadvantages of the above code:

If any exception occurs inside while block it throws exception, the connection.close() process will not executed due to the exception. To avoid this situation, we can take the help of the try....catch... finally block   by closing the connection inside the finally block or inside the catch block.

Advantages of the below code:

"Using" keyword takes the parameter of type IDisposable. Whenever you are using any IDisposable type
object you should use the "using" keyword to handle automatically when it should close or dispose.
Internally using keyword calls the Dispose() method to dispose the IDisposable object.

using (SqlConnection connection = new SqlConnection("connection string"))
{

connection.Open();
using (SqlCommand cmd = new SqlCommand("SELECT * FROM SomeTable", connection))
{

   using (SqlDataReader reader = cmd.ExecuteReader())
   {
         if (reader != null)
        {
             while (reader.Read())
                {
                   //do something
                }
         }
   } // reader closed and disposed up here

// command disposed here
//connection closed and disposed here

7 July 2012

Cloud Computing

Cloud Computing



Cloud computing is the delivery of computing and storage capacity [1] as a service [2] to a heterogeneous community of end-recipients. The name comes from the use of a cloud-shaped symbol[3] as an abstraction for the complex infrastructure it contains in system diagrams[4]. Cloud computing entrusts services with a user's data, software and computation over a network.
There are three types of cloud computing:[5]



Using Infrastructure as a Service, users rent use of servers (as many as needed during the rental period) provided by one or more cloud providers. 
Using Platform as a Service, users rent use of servers and the system software to use in them. 
Using Software as a Service, users also rent application software and databases. The cloud providers manage the infrastructure and platforms on which the applications run.
End users access cloud-based applications through a web browser or a light-weight desktop or mobile app while the business software and user's data are stored on servers at a remote location.
Proponents claim that cloud computing allows enterprises to get their applications up and running faster, with improved manageability and less maintenance, and enables IT to more rapidly adjust resources to meet fluctuating and unpredictable business demand.
Cloud computing relies on sharing of resources to achieve coherence and economies of scale similar to a utility (like theelectricity grid) over a network (typically the Internet). At the foundation of cloud computing is the broader concept of converged infrastructure and shared services.


4 July 2012

CalendarExtender show only years asp.net ajax control

Calendar Extender show only years asp.net ajax control 
reference -> ajaxcontroltoolkit.dll

   < form id="form1" runat="server">
  < ajaxToolkit:ToolkitScriptManager runat="Server" EnableScriptGlobalization="true"
        EnableScriptLocalization="true" ID="ScriptManager1" ScriptMode="Debug" CombineScripts="false" />

<script type="text/javascript" language="javascript">
    function onCalendarShown() {
        var cal = $find("calendar1");
        cal._switchMode("years", true);
        if (cal._yearsBody) {
            for (var i = 0; i < cal._yearsBody.rows.length; i++) {
                var row = cal._yearsBody.rows[i];
                for (var j = 0; j < row.cells.length; j++) {
                    Sys.UI.DomEvent.addHandler(row.cells[j].firstChild, "click", call);
                }
            }
        }
    }

    function onCalendarHidden() {
        var cal = $find("calendar1");
        if (cal._yearsBody) {
            for (var i = 0; i < cal._yearsBody.rows.length; i++) {
                var row = cal._yearsBody.rows[i];
                for (var j = 0; j < row.cells.length; j++) {
                    Sys.UI.DomEvent.removeHandler(row.cells[j].firstChild, "click", call);
                }
            }
        }
    }

    function call(eventElement) {
        var target = eventElement.target;
        switch (target.mode) {
            case "year":
                var cal = $find("calendar1");
                cal.set_selectedDate(target.date);
                cal._blur.post(true);
                cal.raiseDateSelectionChanged(); break;
        }
    }
</script>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="TextBox1_CalendarExtender" runat="server" OnClientHidden="onCalendarHidden"  
 OnClientShown="onCalendarShown" Format="yyyy" BehaviorID="calendar1"  TargetControlID="TextBox1">
</ajaxToolkit:CalendarExtender>
</div>
</form>

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...