Tuesday, 18 November 2014

Difference between Array and Arraylist in C# -.Net

Array
Array List


Arrays are strongly typed collection of same datatype
Array lists are not strongly type collection.
It will store values of same datatype
It will store values of different datatypes or same datatype
these arrays are fixed length that cannot be changed during runtime.
Array list size will increase or decrease dynamically it can take any size of values from any data type. 

Arrays belong to System.Array namespace
 Array lists will be accessible with “System.Collections” namespace
string[] arr=new string[2];
arr[0] = "text1";
arr[1] = "text2 ";

ArrayList strarr = new ArrayList();
strarr.Add("text"); // Add string values
strarr.Add(10);   // Add integer values
strarr.Add(10.05); // Add float values

ASP.NET vNext

ASP.NET vNext

  • 1.       ASP.NET vNext includes new cloud-optimized versions of MVC, Web API, Web Pages, SignalR, and Entity Framework.
  • 2.       MVC, Web API and Web Pages have been merged into one framework, called MVC 6. This will follow common programming approach between all these three i.e. a single programming model for Web sites and services.
  • For example, there is unified controller, routing concepts, action selection, filters, model binding, and so on. In this way, You will have a single controller that returns both MVC views and formatted Web API responses, on the same HTTP verb.
  • 3.       MVC 6 has no dependency on System.Web since it was quite expensive. A typical HttpContext object graph can consume 30K of memory per request and working with small JSON-style requests this is very costly. With MVC 6 it is reduced to roughly 2K. The result is a leaner framework, with faster startup time and lower memory consumption.
  • 4.       ASP.NET vNext has new project extension project.json to list all the dependencies for the application and astartup class in place of Global.asax.
  • 5.       ASP.NET vNext apps are cloud ready by design. Services such as session state and caching will adjust their behavior depending on hosting environment either it is cloud or a traditional hosting environment. It uses dependency injection behind the scenes to provide your app with the correct implementation for these services for cloud or a traditional hosting environment. In this way, it will easy to move your app from on-premises to the cloud, since you need not to change your code.
  • 6.       .NET next version, .NET vNext is host agnostic. Hence you can host your ASP.NET vNEXT app in IIS, or self-host in a custom process.


Monday, 17 November 2014

What's the difference between String and string?



String


  • Stands for System.String                
  • It is a .NET Framework type



string

  • string is an alias in the C# language for System.String

Difference Between Equality Operator ( ==) and Equals() Method in C#

Difference Between Equality Operator ( ==) and Equals() Method in C#



The Equality Operator ( ==)                                                        Equals() method

Comparison operator                                                                      Compares the contents of a string
Compares the reference identity                                                     Compares only contents

MVC Tutorial Links

MVC Tutorials Links

http://www.codeproject.com/Articles/667369/ASP-NET-MVC-Learning-Roadmap

Sunday, 16 November 2014

Calling A Button OnClick from a function

Suppose you have a function test() and button. You want to call button click event from function automatically, you can do as:

private void ExtractedMethod()
{ 
 //some list of code
Button_Click(null, EventArgs.Empty);
}
protected void Button_Click(object sender, EventArgs e)
 {
  //some list of code     }

Sunday, 9 November 2014

Update data row of dataset /datatable

If you want to update the row based on column value of dataset / datatable , you will do as:

Suppose you have a dataset named dataset1 having table with name TableName". Table have 2 column named ColumnName1, ColumnName2, ColumnName3.

You want to update Row having ColumnName1='Value1'

DataRow[] Row = dataSet1.Tables["TableName"].Select("ColumnName1= 'Value1'");

Row [0]["ColumnName2"] = "Value2";
Row [0]["ColumnName3"] = "Value3";



Tuesday, 4 November 2014

Refresh parent window on close of child window in asp.net

Code to refresh parent window on close of child window.

Put the below code in <head> tag of aspx page of child window.

<script type="text/jscript">
        window.onunload = refreshParent;
        function refreshParent() {
            var loc = window.opener.location;
            window.opener.location = loc;
        }
</script>

Close the Page on a Button Click asp.net c#.

If you want to close the window after executing code behind code.


string closeWindowScript = "<script language=javascript>window.top.close();</script>";
if ((!ClientScript.IsStartupScriptRegistered("clientScript"))) {
ClientScript.RegisterStartupScript(Page.GetType(), "clientScript", closeWindowScript);
}

open new browser window on button click event in asp.net

Suppose you want to open a window from code behind on button click or other event in asp.net, you just following code as per your requirement.

 protected void button_Click(object sender, EventArgs e)
    {
        // open a pop up window at the center of the page.
        ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft                           = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);                                window.open( 'your_page.aspx', null, 'height=700,width=760,                               status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,                               top=\'+Mtop+\', left=\'+Mleft+\'' );", true);
    }