<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Toars &#187; .NET</title>
	<atom:link href="http://www.toars.com/category/programming/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.toars.com</link>
	<description>I will smile to the world ^o^</description>
	<lastBuildDate>Fri, 06 May 2011 08:50:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>(1/3) ListView events, ItemDataBound, ItemCreated</title>
		<link>http://www.toars.com/2010/11/listview-events-01/</link>
		<comments>http://www.toars.com/2010/11/listview-events-01/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 11:54:35 +0000</pubDate>
		<dc:creator>Xin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.toars.com/?p=511</guid>
		<description><![CDATA[Below are the screenshots about a user control that is using the .NET ListView control. Display Record The ListView control contains many different events. In these examples, the EDIT button, REMOVE button, ADD button, and SAVE button click events are handled respectively. Of course, there are many ways of implementations to get the job done, as far [...]]]></description>
			<content:encoded><![CDATA[<p>Below are the screenshots about a user control that is using the .NET <strong>ListView </strong>control.</p>
<p style="text-align: center;"><a href="http://www.toars.com/wp-content/uploads/2010/11/DNS-A-Record-Display.jpg" target="_blank"> <img class="size-full wp-image-516 aligncenter" title="DNS-A-Record-Display" src="http://www.toars.com/wp-content/uploads/2010/11/DNS-A-Record-Display.jpg" alt="" width="680" />Display Record</a></p>
<p>The <strong>ListView </strong>control contains many different events. In these examples, the <strong>EDIT </strong>button, <strong>REMOVE </strong>button, <strong>ADD </strong>button, and <strong>SAVE </strong>button click events are handled respectively.</p>
<p>Of course, there are many ways of implementations to get the job done, as far as I believed, using these <strong>ItemDataBound</strong>, <strong>ItemEditing</strong>, <strong>ItemDeleting</strong>, <strong>ItemCanceling</strong>, <strong>ItemUpdating</strong>, and <strong>ItemInserting </strong>are the easiest way.</p>
<p>Before implementing the code, design the UI first.</p>
<pre>
<div id="_mcePaste"><strong>&lt;table&gt;
&lt;thead&gt;
    &lt;tr&gt;
        &lt;th&gt;&lt;asp:Literal ID="LitHost" runat="server" /&gt;&lt;/th&gt;
        &lt;th&gt;&lt;asp:Literal ID="LitPointsTo" runat="server" /&gt;&lt;/th&gt;
        &lt;th&gt;&lt;asp:Literal ID="LitTtl" runat="server" /&gt;&lt;/th&gt;
        &lt;th&gt;&lt;asp:Literal ID="LitActions" runat="server" /&gt;&lt;/th&gt;
    &lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
    &lt;asp:ListView ID="LstItems" runat="server"&gt;
        &lt;LayoutTemplate&gt;
            &lt;tr id="itemPlaceHolder" runat="server" /&gt;
        &lt;/LayoutTemplate&gt;
        &lt;ItemTemplate&gt;
            &lt;tr&gt;
                &lt;td&gt;&lt;asp:Literal ID="LitHost" runat="server" /&gt;&lt;/td&gt;
                &lt;td&gt;&lt;asp:Literal ID="LitPointsTo" runat="server" /&gt;&lt;/td&gt;
                &lt;td&gt;&lt;asp:Literal ID="LitTtl" runat="server" /&gt;&lt;/td&gt;
                &lt;td&gt;
                    &lt;asp:LinkButton CommandName="Edit" ID="BtnEdit" runat="server" /&gt;
                    &lt;asp:LinkButton CommandName="Delete" ID="BtnRemove" runat="server" /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
        &lt;/ItemTemplate&gt;
        &lt;EditItemTemplate&gt;
            &lt;tr&gt;
                &lt;td&gt;&lt;asp:TextBox ID="TxtHost" runat="server" /&gt;&lt;/td&gt;
                &lt;td&gt;&lt;asp:TextBox ID="TxtPointsTo" runat="server" /&gt;&lt;/td&gt;
                &lt;td&gt;&lt;asp:DropDownList ID="DdlTtl" runat="server" /&gt;&lt;/td&gt;
                &lt;td&gt;
                    &lt;asp:LinkButton CommandName="Update" ID="BtnSave" runat="server" /&gt;
                    &lt;asp:LinkButton CommandName="Cancel" ID="BtnCancel" runat="server" /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
        &lt;/EditItemTemplate&gt;
        &lt;InsertItemTemplate&gt;
            &lt;tr&gt;
                &lt;td&gt;&lt;asp:TextBox ID="TxtNewHost" runat="server" /&gt;&lt;/td&gt;
                &lt;td&gt;&lt;asp:TextBox ID="TxtNewPointsTo" runat="server" /&gt;&lt;/td&gt;
                &lt;td&gt;&lt;asp:DropDownList ID="DdlNewTtl" runat="server" /&gt;&lt;/td&gt;
                &lt;td&gt;&lt;asp:LinkButton ID="BtnAdd" CommandName="Insert" runat="server" /&gt;&lt;/td&gt;
            &lt;/tr&gt;
        &lt;/InsertItemTemplate&gt;
    &lt;/asp:ListView&gt;
&lt;/tbody&gt;
&lt;/table&gt;</strong></div>
</pre>
<p>In the code-behind, we need to hook up the <strong>ItemDataBound </strong>event, and bind the data source.</p>
<pre>
<div id="_mcePaste">
<strong>LstItems.ItemDataBound += new EventHandler&lt;ListViewItemEventArgs&gt;(LstItems_ItemDataBound);

LstItems.DataSource = DnsCollection;
LstItems.DataBind();</strong></div>
</pre>
<p>It is more flexible to handle the <strong>ItemDataBound </strong>event in the code-behind than binding the data source in the UI.</p>
<pre>
<div id="_mcePaste"><strong>
protected void LstItems_ItemDataBound(object sender, ListViewItemEventArgs e)
{
    var item = e.Item;
    if (item.ItemType == ListViewItemType.DataItem)
    {
        var currentDnsRecord = (DnsRecordItem)(item as ListViewDataItem).DataItem;

        // When Displaying the items
        if (item.DataItemIndex != LstItems.EditIndex)
        {
            var litHost = item.FindControl&lt;Literal&gt;("LitHost");
            var litPointsTo = item.FindControl&lt;Literal&gt;("LitPointsTo");
            var litTtl = item.FindControl&lt;Literal&gt;("LitTtl");

            litHost.Text = currentDnsRecord.HostName;
            litPointsTo.Text = currentDnsRecord.PointsTo;
            litTtl.Text = currentDnsRecord.TimeToLive;
        }
        else
        {   // When rendering Edit item.
            var txtHost = item.FindControl&lt;TextBox&gt;("TxtHost");
            var txtPointsTo = item.FindControl&lt;TextBox&gt;("TxtPointsTo");
            var ddlTtl = item.FindControl&lt;DropDownList&gt;("DdlTTL");

            txtHost.Text = OldDnsRecord.HostName;
            txtPointsTo.Text = OldDnsRecord.PointsTo;
            BindDdlTimeToLive(ddlTtl, OldDnsRecord.TimeToLive);
        }
    }
}</strong></div>
</pre>
<p>If you are not quite sure the FindControl, please check my previous post, <a href="http://www.toars.com/2010/03/dot-net-c-sharp-findcontrol-extension-method-findcontrolsbytype-findcontrolrecursive/" target="_blank">FindControl() Extention methods</a>.</p>
<p>On the other hand, when you want to do something before <strong>ItemDataBound </strong>event, you can create this <strong>ItemCreated </strong>event handler.</p>
<pre>
<div id="_mcePaste">
<strong>LstItems.ItemCreated += new EventHandler&lt;ListViewItemEventArgs&gt;(LstItems_ItemCreated);
</strong></div>
</pre>
<p><strong>ItemCreated </strong> is happened when the ListView is created, and when the data items are bound to the control.<br />
<strong>ItemCreated </strong> is raised before the <strong>ItemDataBound </strong>event.</p>
<pre>
<div id="_mcePaste"><strong>
protected void LstItems_ItemCreated(object sender, ListViewItemEventArgs e)
{
    var item = e.Item;

    if (item.ItemType == ListViewItemType.DataItem)
    {
    }
    else if (item.ItemType == ListViewItemType.InsertItem)
    {
    }
}
</strong></div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.toars.com/2010/11/listview-events-01/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>(2/5) ListView events, ItemInserting, ItemDeleting</title>
		<link>http://www.toars.com/2010/11/listview-events-02/</link>
		<comments>http://www.toars.com/2010/11/listview-events-02/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 12:43:00 +0000</pubDate>
		<dc:creator>Xin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.toars.com/?p=557</guid>
		<description><![CDATA[Add Record In order to have this ADD button work, what we need is to wire the events first in the page's code behind. LstItems.ItemInserting += new EventHandler&#60;ListViewInsertEventArgs&#62;(LstItems_ItemInserting); LstItems.ItemDeleting += new EventHandler&#60;ListViewInsertEventArgs&#62;(LstItems_ItemDeleting); LstItems.InsertItemPosition = InsertItemPosition.LastItem; And usually, we will have this insert template either in the first item of this ListView or the last item. [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://www.toars.com/wp-content/uploads/2010/11/DNS-A-Record-Add.jpg"> <img class="aligncenter size-full wp-image-515" title="DNS-A-Record-Add" src="http://www.toars.com/wp-content/uploads/2010/11/DNS-A-Record-Add.jpg" alt="" width="680" />Add Record</a></p>
<p>In order to have this <strong>ADD </strong>button work, what we need is to wire the events first in the page's code behind.</p>
<pre><strong>LstItems.ItemInserting += new EventHandler&lt;ListViewInsertEventArgs&gt;(LstItems_ItemInserting);</strong></pre>
<pre><strong>LstItems.ItemDeleting += new EventHandler&lt;ListViewInsertEventArgs&gt;(LstItems_ItemDeleting);</strong></pre>
<pre><strong>LstItems.InsertItemPosition = InsertItemPosition.LastItem;
</strong></pre>
<p>And usually, we will have this insert template either in the first item of this <strong>ListView </strong>or the last item. In this example, it is in the last item.</p>
<p><strong>Button "Add" click.</strong></p>
<pre><strong>protected void LstItems_ItemInserting(object sender, ListViewInsertEventArgs e)
{
    if (!Page.IsValid)
    return;

    var txtNewHost = e.Item.FindControl&lt;TextBox&gt;("TxtNewHost");
    var txtNewPointsTo = e.Item.FindControl&lt;TextBox&gt;("TxtNewPointsTo");
    var ddlNewTtl = e.Item.FindControl&lt;DropDownList&gt;("DdlNewTTL");

    var host = txtNewHost.Text;
    var pointsTo = txtNewPointsTo.Text;
    var ttl = ddlNewTtl.SelectedValue;

    var result = AddNewRecord();
    if (result == Status.Ok)
    {
        // Rebind the ListView
    }
    else
    {
        // Do error handling
    }
}
</strong></pre>
<pre><strong>
</strong></pre>
<p><strong>Button "Remove" click.</strong></p>
<pre><strong>protected void LstItems_ItemDeleting(object sender, ListViewInsertEventArgs e)
{
    var item = LstItems.Items[e.ItemIndex];

    var result = RemoveRecord();
    if (result == Status.Ok)
    {
        LstItems.EditIndex = -1;

        // Rebind the ListView
    }
    else
    {
        // Do error handling
    }
}
</strong></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.toars.com/2010/11/listview-events-02/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(3/3) ListView events, ItemEditing, ItemCanceling, ItemUpdating</title>
		<link>http://www.toars.com/2010/11/listview-events-03/</link>
		<comments>http://www.toars.com/2010/11/listview-events-03/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 12:36:32 +0000</pubDate>
		<dc:creator>Xin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.toars.com/?p=552</guid>
		<description><![CDATA[Edit Record Same for this Edit Record, Save Record and Cancel button click events. Wire the events in the code-behind first. LstItems.ItemEditing += new EventHandler&#60;ListViewItemEventArgs&#62;(LstItems_ItemEditing); LstItems.ItemUpdating += new EventHandler&#60;ListViewItemEventArgs&#62;(LstItems_ItemUpdating); LstItems.ItemCanceling += new EventHandler&#60;ListViewItemEventArgs&#62;(LstItems_ItemCanceling); Button "Edit" click. protected void LstItems_ItemEditing(object sender, ListViewItemEventArgs e) { var item = LstItems.Items[e.NewEditIndex]; // Save the currently selected item to OldDnsRecord [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://www.toars.com/wp-content/uploads/2010/11/DNS-A-Record-Edit.jpg"><br />
<img class="aligncenter size-full wp-image-517" title="DNS-A-Record-Edit" src="http://www.toars.com/wp-content/uploads/2010/11/DNS-A-Record-Edit.jpg" alt="" width="680" />Edit Record</a></p>
<p>Same for this <strong>Edit Record</strong>, <strong>Save Record</strong> and <strong>Cancel</strong> button click events.</p>
<p>Wire the events in the code-behind first.</p>
<pre>
<div id="_mcePaste"><strong>LstItems.ItemEditing += new EventHandler&lt;ListViewItemEventArgs&gt;(LstItems_ItemEditing);
LstItems.ItemUpdating += new EventHandler&lt;ListViewItemEventArgs&gt;(LstItems_ItemUpdating);
LstItems.ItemCanceling += new EventHandler&lt;ListViewItemEventArgs&gt;(LstItems_ItemCanceling);</strong></div>
</pre>
<p><strong>Button "Edit" click.</strong></p>
<pre>
<div id="_mcePaste"><strong>protected void LstItems_ItemEditing(object sender, ListViewItemEventArgs e)
{
    var item = LstItems.Items[e.NewEditIndex];

    // Save the currently selected item to OldDnsRecord</strong></div>
<div id="_mcePaste"><strong>
    // ReBind the ListView
}
</strong></div>
</pre>
<p><strong>Button "Save" click.</strong></p>
<pre>
<div id="_mcePaste"><strong>protected void LstItems_ItemUpdating(object sender, ListViewItemEventArgs e)
{
    if (!Page.IsValid)
    return;

    var txtNewHost = e.Item.FindControl&lt;TextBox&gt;("TxtNewHost");
    var txtNewPointsTo = e.Item.FindControl&lt;TextBox&gt;("TxtNewPointsTo");
    var ddlNewTtl = e.Item.FindControl</strong><strong>&lt;DropDownList&gt;("DdlNewTTL");

    var host = txtNewHost.Text;
    var pointsTo = txtNewPointsTo.Text;
    var ttl = ddlNewTtl.SelectedValue;

    var result = UpdateExistingRecord();
    if (result == Status.Ok)
    {
        LstItems.EditIndex = -1;

        // Rebind the ListView
    }
    else
    {
        // Do error handling
    }
}
</strong></div>
</pre>
<p><strong>Button "Cancel" click.</strong></p>
<pre>
<div id="_mcePaste"><strong>protected void LstItems_ItemCanceling(object sender, ListViewItemEventArgs e)
{
        LstItems.EditIndex = -1;

        // Rebind the ListView
}
</strong></div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.toars.com/2010/11/listview-events-03/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET Events</title>
		<link>http://www.toars.com/2010/11/asp-net-events/</link>
		<comments>http://www.toars.com/2010/11/asp-net-events/#comments</comments>
		<pubDate>Sun, 14 Nov 2010 10:41:30 +0000</pubDate>
		<dc:creator>Xin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.toars.com/?p=487</guid>
		<description><![CDATA[HttpApplication.BeginRequest HttpApplication.AuthenticateRequest HttpApplication.PostAuthenticateRequest HttpApplication.AuthorizeRequest HttpApplication.PostAuthorizeRequest HttpApplication.ResolveRequestCache HttpApplication.PostResolveRequestCache HttpApplication.MapRequestHandler HttpApplication.PostMapRequestHandler HttpApplication.AcquireRequestState HttpApplication.PostAcquireRequestState HttpApplication.PreRequestHandlerExecute Page.FrameworkInitialize Page.InitializeCulture Page.OnPreInit MasterPage.FrameworkInitialize MasterPageControl.FrameworkInitialize PageControl.FrameworkInitialize MasterPageControl.OnInit PageControl.OnInit MasterPage.OnInit Page.OnInit Page.OnInitComplete Page.LoadPageStateFromPersistenceMedium If IsPostBack Page.LoadControlState If IsPostBack MasterPageControl.LoadControlState If IsPostBack, RegisterRequiresControlState was called and control state contains elements PageControl.LoadControlState If IsPostBack, RegisterRequiresControlState was called and control state contains elements MasterPageControl.LoadViewState If IsPostBack and [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li><strong>HttpApplication.BeginRequest</strong></li>
<li><strong>HttpApplication.AuthenticateRequest</strong></li>
<li><strong>HttpApplication.PostAuthenticateRequest</strong></li>
<li><strong>HttpApplication.AuthorizeRequest</strong></li>
<li><strong>HttpApplication.PostAuthorizeRequest</strong></li>
<li><strong>HttpApplication.ResolveRequestCache</strong></li>
<li><strong>HttpApplication.PostResolveRequestCache</strong></li>
<li><strong>HttpApplication.MapRequestHandler</strong></li>
<li><strong>HttpApplication.PostMapRequestHandler</strong></li>
<li><strong>HttpApplication.AcquireRequestState</strong></li>
<li><strong>HttpApplication.PostAcquireRequestState</strong></li>
<li><strong>HttpApplication.PreRequestHandlerExecute</strong></li>
<li><strong>Page.FrameworkInitialize</strong></li>
<li><strong>Page.InitializeCulture</strong></li>
<li><strong>Page.OnPreInit</strong></li>
<li><strong>MasterPage.FrameworkInitialize</strong></li>
<li><strong>MasterPageControl.FrameworkInitialize</strong></li>
<li><strong>PageControl.FrameworkInitialize</strong></li>
<li><strong>MasterPageControl.OnInit</strong></li>
<li><strong>PageControl.OnInit</strong></li>
<li><strong>MasterPage.OnInit</strong></li>
<li><strong>Page.OnInit</strong></li>
<li><strong>Page.OnInitComplete</strong></li>
<li><strong>Page.LoadPageStateFromPersistenceMedium</strong><br />
If <strong>IsPostBack</strong></li>
<li><strong>Page.LoadControlState</strong><br />
If <strong>IsPostBack</strong></li>
<li><strong>MasterPageControl.LoadControlState</strong><br />
If <strong>IsPostBack</strong>, <strong>RegisterRequiresControlState</strong> was called and control state contains elements</li>
<li><strong>PageControl.LoadControlState</strong><br />
If <strong>IsPostBack</strong>, <strong>RegisterRequiresControlState</strong> was called and control state contains elements</li>
<li><strong>MasterPageControl.LoadViewState </strong><br />
If <strong>IsPostBack </strong>and <strong>ViewState </strong>contains elements</li>
<li><strong>PageControl.LoadViewState</strong><br />
If <strong>IsPostBack </strong>and <strong>ViewState </strong>contains elements</li>
<li><strong>Page.OnPreLoad</strong></li>
<li><strong>Page.OnLoad</strong></li>
<li><strong>MasterPage.OnLoad</strong></li>
<li><strong>MasterPageControl.OnLoad</strong></li>
<li><strong>PageControl.OnLoad</strong></li>
<li><strong>{PageControl|MasterPageControl}.OnCustomEvent</strong><br />
If a custom event was fired on a control declared on the page/master page</li>
<li><strong>{PageControl|MasterPageControl}.OnBubbleEvent </strong><br />
If a custom event was fired on a control declared on the page/master page</li>
<li><strong>{Page|MasterPage}.OnBubbleEvent</strong><br />
If a custom event was fired on a control declared on the page/master page</li>
<li><strong>Page.OnBubbleEvent</strong><br />
If a custom event was fired</li>
<li><strong>Page.OnLoadComplete</strong></li>
<li><strong>ClientCallbackControl.RaiseCallbackEvent</strong><br />
If in a client callback asynchronous request</li>
<li><strong>ClientCallbackControl.GetCallbackResult</strong><br />
If in a client callback asynchronous request</li>
<li><strong>Page.OnPreRender</strong><br />
If not in an asynchronous postback</li>
<li><strong>MasterPage.OnPreRender</strong><br />
If not in an asynchronous postback</li>
<li><strong>MasterPageControl.OnPreRender</strong><br />
If <strong>Visible</strong></li>
<li><strong>PageControl.OnPreRender</strong><br />
If <strong>Visible </strong>and not in an asynchronous postback</li>
<li><strong>Page.OnPreRenderComplete</strong><br />
If not in an asynchronous postback</li>
<li><strong>Page.SaveControlState</strong><br />
If not in an asynchronous postback and <strong>RegisterRequiresControlState </strong>is called for the page and control state contains additiona values</li>
<li><strong>MasterPageControl.SaveControlState</strong><br />
If not in an asynchronous postback and <strong>RegisterRequiresControlState </strong>is called for the master page control and control state contains additiona values</li>
<li><strong>PageControl.SaveControlState</strong><br />
If not in an asynchronous postback and <strong>RegisterRequiresControlState </strong>is called for the page control and control state contains additiona values</li>
<li><strong>Page.SaveViewState</strong><br />
If not in an asynchronous postback</li>
<li><strong>MasterPage.SaveViewState</strong><br />
If not in an asynchronous postback</li>
<li><strong>MasterPageControl.SaveViewState</strong><br />
If not in an asynchronous postback</li>
<li><strong>PageControl.SaveViewState</strong><br />
If not in an asynchronous postback</li>
<li><strong>Page.SavePageStateToPersistenceMedium</strong><br />
If not in an asynchronous postback</li>
<li><strong>Page.OnSaveStateComplete</strong><br />
If not in an asynchronous postback</li>
<li><strong>Page.Render</strong><br />
If not in an asynchronous postback</li>
<li><strong>MasterPage.Render</strong><br />
If not in an asynchronous postback</li>
<li><strong>MasterPageControl.Render</strong><br />
If <strong>Visible </strong>and not in an asynchronous postback</li>
<li><strong>PageControl.Render</strong><br />
If <strong>Visible </strong>and not in an asynchronous postback</li>
<li><strong>Page.OnCommitTransaction</strong><br />
If <strong>Transaction </strong>= <strong>Required </strong>or <strong>RequiresNew </strong>and a transaction was committed or no transaction was created</li>
<li><strong>Page.OnAbortTransaction</strong><br />
If <strong>Transaction </strong>= <strong>Required </strong>or <strong>RequiresNew </strong>and a transaction was rolled back</li>
<li><strong>MasterPageControl.OnUnload</strong></li>
<li><strong>MasterPageControl.Dispose</strong></li>
<li><strong>PageControl.OnUnload</strong></li>
<li><strong>PageControl.Dispose</strong></li>
<li><strong>MasterPage.OnUnload</strong></li>
<li><strong>MasterPage.Dispose</strong></li>
<li><strong>Page.OnUnload</strong></li>
<li><strong>Page.Dispose</strong></li>
<li><strong>HttpApplication.PostRequestHandlerExecute</strong></li>
<li><strong>HttpApplication.ReleaseRequestState</strong></li>
<li><strong>HttpApplication.PostReleaseRequestState</strong></li>
<li><strong>HttpApplication.UpdateRequestCache</strong></li>
<li><strong>HttpApplication.PostUpdateRequestCache</strong></li>
<li><strong>HttpApplication.LogRequest</strong></li>
<li><strong>HttpApplication.PostLogRequest</strong></li>
<li><strong>HttpApplication.EndRequest</strong></li>
<li><strong>HttpApplication.PreSendRequestHeaders</strong></li>
<li><strong>HttpApplication.PreSendRequestContent</strong></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.toars.com/2010/11/asp-net-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET Page life cycle</title>
		<link>http://www.toars.com/2010/11/asp-net-page-life-cycle/</link>
		<comments>http://www.toars.com/2010/11/asp-net-page-life-cycle/#comments</comments>
		<pubDate>Sun, 14 Nov 2010 10:27:52 +0000</pubDate>
		<dc:creator>Xin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.toars.com/?p=483</guid>
		<description><![CDATA[Page.OnPreInit MasterPageControl.OnInit (for each control on the master page) Control.OnInit (for each contol on the page) MasterPage.OnInit Page.OnInit Page.OnInitComplete Page.LoadPageStateFromPersistenceMedium Page.LoadViewState MasterPage.LoadViewState Page.OnPreLoad Page.OnLoad MasterPage.OnLoad MasterPageControl.OnLoad (for each control on the master page) Control.OnLoad (for each control on the page) OnXXX (control event) MasterPage.OnBubbleEvent Page.OnBubbleEvent Page.OnLoadComplete Page.OnPreRender MasterPage.OnPreRender MasterPageControl.OnPreRender (for each control on the master [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li>Page.OnPreInit</li>
<li>MasterPageControl.OnInit (for each control on the master page)</li>
<li>Control.OnInit (for each contol on the page)</li>
<li>MasterPage.OnInit</li>
<li>Page.OnInit</li>
<li>Page.OnInitComplete</li>
<li>Page.LoadPageStateFromPersistenceMedium</li>
<li>Page.LoadViewState</li>
<li>MasterPage.LoadViewState</li>
<li>Page.OnPreLoad</li>
<li>Page.OnLoad</li>
<li>MasterPage.OnLoad</li>
<li>MasterPageControl.OnLoad (for each control on the master page)</li>
<li>Control.OnLoad (for each control on the page)</li>
<li>OnXXX (control event)</li>
<li>MasterPage.OnBubbleEvent</li>
<li>Page.OnBubbleEvent</li>
<li>Page.OnLoadComplete</li>
<li>Page.OnPreRender</li>
<li>MasterPage.OnPreRender</li>
<li>MasterPageControl.OnPreRender (for each control on the master page)</li>
<li>Control.OnPreRender (for each control on the page)</li>
<li>Page.OnPreRenderComplete</li>
<li>MasterPageControl.SaveControlState (for each control on the master  page)</li>
<li>Control.SaveControlState (for each control on the page)</li>
<li>Page.SaveViewState</li>
<li>MasterPage.SaveViewState</li>
<li>Page.SavePageStateToPersistenceMedium</li>
<li>Page.OnSaveStateComplete</li>
<li>MasterPageControl.OnUnload (for each control on the master page)</li>
<li>Control.OnUnload (for each control on the page)</li>
<li>MasterPage.OnUnload</li>
<li>Page.OnUnload</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.toars.com/2010/11/asp-net-page-life-cycle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# Questions and Answers &#8211; 09</title>
		<link>http://www.toars.com/2010/11/c-sharp-questions-and-answers-09/</link>
		<comments>http://www.toars.com/2010/11/c-sharp-questions-and-answers-09/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 11:22:20 +0000</pubDate>
		<dc:creator>Xin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Interviews]]></category>

		<guid isPermaLink="false">http://www.toars.com/?p=447</guid>
		<description><![CDATA[How big is the datatype int in .NET? 32 bits. How big is the char? 16 bits (Unicode). How do you initiate a string without escaping each backslash? Put an @ sign in front of the double-quoted string. What are valid signatures for the Main function? public static void Main() public static int Main() public [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li><strong>How big is the datatype int in .NET?</strong><br />
32 bits.</li>
<li><strong>How big is the char?</strong><br />
16 bits (Unicode).</li>
<li><strong>How do you initiate a string without escaping each backslash? </strong><br />
Put an  @ sign in front of the double-quoted string.</li>
<li><strong>What are valid signatures for the Main function? </strong>
<ul type="disc">
<li>public static void Main()</li>
<li>public static int Main()</li>
<li>public static void Main( string[] args )</li>
<li>public static int Main(string[] args )</li>
</ul>
</li>
<li><strong>Does Main() always have to be public?</strong><br />
No.</li>
<li><strong>How do you initialize a two-dimensional array that you don’t know the  dimensions of?</strong>
<ul type="disc">
<li>int [, ] myArray; //declaration</li>
<li>myArray= new int [5, 8]; //actual initialization</li>
</ul>
</li>
<li><strong>What’s the access level of the visibility type internal? </strong><br />
Current  assembly.</li>
<li><strong>What’s the difference between struct and class in C#?</strong>
<ul type="disc">
<li>Structs cannot be inherited.</li>
<li>Structs are passed by value, not by reference.</li>
<li>Struct is stored on the stack, not the heap.</li>
</ul>
</li>
<li><strong>Explain encapsulation</strong><br />
The implementation is hidden, the interface is  exposed.</li>
<li><strong>What data type should you use if you want an 8-bit value that’s  signed?</strong><br />
sbyte.</li>
<li><strong>Speaking of Boolean data types, what’s different between C# and  C/C++?</strong><br />
There’s no conversion between 0 and false, as well as any other  number and true, like in C/C++.</li>
<li><strong>Where are the value-type variables allocated in the computer RAM?</strong><br />
Stack.</li>
<li><strong>Where do the reference-type variables go in the RAM? </strong><br />
The references  go on the stack, while the objects themselves go on the heap. However, <a href="http://www.yoda.arachsys.com/csharp/memory.html">in reality things are  more elaborate</a>.</li>
<li><strong>What is the difference between the value-type variables and  reference-type variables in terms of garbage collection? </strong><br />
The value-type  variables are not garbage-collected, they just fall off the stack when they fall  out of scope, the reference-type objects are picked up by GC when their  references go null.</li>
<li><strong>How do you convert a string into an integer in .NET? </strong><br />
Int32.Parse(string), Convert.ToInt32()</li>
<li><strong>How do you box a primitive data type variable? </strong><br />
Initialize an object  with its value, pass an object, cast it to an object</li>
<li><strong>Why do you need to box a primitive variable? </strong><br />
To pass it by reference  or apply a method that an object supports, but primitive doesn’t.</li>
<li><strong>What’s the difference between Java and .NET garbage collectors? </strong><br />
Sun  left the implementation of a specific garbage collector up to the JRE developer,  so their performance varies widely, depending on whose JRE you’re using.  Microsoft standardized on their garbage collection.</li>
<li><strong>How do you enforce garbage collection in .NET? </strong><br />
System.GC.Collect();</li>
<li><strong>Can you declare a C++ type destructor in C# like ~MyClass()? </strong><br />
Yes, but  what’s the point, since it will call Finalize(), and Finalize() has no  guarantees when the memory will be cleaned up, plus, it introduces additional  load on the garbage collector. The only time the finalizer should be  implemented, is when you’re dealing with unmanaged code.</li>
<li><strong>What’s different about namespace declaration when comparing that to  package declaration in Java? </strong><br />
No semicolon. Package declarations also have to  be the first thing within the file, can’t be nested, and affect all classes  within the file.</li>
<li><strong>What’s the difference between const and readonly? </strong><br />
You can initialize  readonly variables to some runtime values. Let’s say your program uses current  date and time as one of the values that won’t change. This way you declare</p>
<blockquote><p>public readonly string DateT = new DateTime().ToString().</p></blockquote>
</li>
<li><strong>Can you create enumerated data types in C#?</strong><br />
Yes.</li>
<li><strong>What’s different about switch statements in C# as compared to C++? </strong><br />
No  fall-throughs allowed.</li>
<li><strong>What happens when you encounter a continue statement inside the for loop? </strong><br />
The code for the rest of the loop is ignored, the control is transferred  back to the beginning of the loop.</li>
<li><strong>Is goto statement supported in C#? How about Java? </strong><br />
Gotos are  supported in C#to the fullest. In Java goto is a reserved keyword that provides  absolutely no functionality.</li>
<li><strong>Describe the compilation process for .NET code?</strong><br />
Source code is  compiled and run in the .NET Framework using a two-stage process. First, source  code is compiled to Microsoft intermediate language (MSIL) code using a .NET  Framework-compatible compiler, such as that for Visual Basic .NET or Visual C#.  Second, MSIL code is compiled to native code.</li>
<li><strong>Name any 2 of the 4 .NET authentification methods</strong><br />
ASP.NET, in  conjunction with Microsoft Internet Information Services (IIS), can authenticate  user credentials such as names and passwords using any of the following  authentication methods:</p>
<ul>
<li>Windows: Basic, digest, or Integrated Windows Authentication (NTLM or  Kerberos).</li>
<li>Microsoft Passport authentication</li>
<li>Forms authentication</li>
<li>Client Certificate authentication</li>
</ul>
</li>
<li><strong>How do you turn off SessionState in the web.config file?</strong><br />
In the  system.web section of web.config, you should locate the httpmodule tag and you  simply disable session by doing a remove tag with attribute name set to  session.</p>
<blockquote><p>&lt;httpModules&gt;<br />
&lt;remove name=”Session”  /&gt;<br />
&lt;/httpModules&gt;</p></blockquote>
</li>
<li><strong>What is main difference between Global.asax and Web.Config? </strong><br />
ASP.NET  uses the global.asax to establish any global objects that your Web application  uses. The .asax extension denotes an application file rather than .aspx for a  page file. Each ASP.NET application can contain at most one global.asax file.  The file is compiled on the first page hit to your Web application. ASP.NET is  also configured so that any attempts to browse to the global.asax page directly  are rejected. However, you can specify application-wide settings in the  web.config file. The web.config is an XML-formatted text file that resides in  the Web site’s root directory. Through Web.config you can specify settings like  custom 404 error pages, authentication and authorization settings for the Web  site, compilation options for the ASP.NET Web pages, if tracing should be  enabled, etc.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.toars.com/2010/11/c-sharp-questions-and-answers-09/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# Questions and Answers &#8211; 08</title>
		<link>http://www.toars.com/2010/11/c-sharp-questions-and-answers-08/</link>
		<comments>http://www.toars.com/2010/11/c-sharp-questions-and-answers-08/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 11:21:58 +0000</pubDate>
		<dc:creator>Xin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Interviews]]></category>

		<guid isPermaLink="false">http://www.toars.com/?p=445</guid>
		<description><![CDATA[What’s the implicit name of the parameter that gets passed into the class’ set method? Value, and it’s datatype depends on whatever variable we’re changing. How do you inherit from a class in C#? Place a colon and then the name of the base class. Does C# support multiple inheritance? No, use interfaces instead. When [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li><strong>What’s the implicit name of the parameter that gets passed into the  class’ set method?</strong><br />
Value, and it’s datatype depends on whatever variable  we’re changing.</li>
<li><strong>How do you inherit from a class in C#? </strong><br />
Place a colon and then the  name of the base class.</li>
<li><strong>Does C# support multiple inheritance? </strong><br />
No, use interfaces  instead.</li>
<li><strong>When you inherit a protected class-level variable, who is it available  to? </strong><br />
Classes in the same namespace.</li>
<li><strong>Are private class-level variables inherited? </strong><br />
Yes, but they are not  accessible, so looking at it you can honestly say that they are not inherited.  But they are.</li>
<li><strong>Describe the accessibility modifier protected internal. </strong><br />
It’s  available to derived classes and classes within the same Assembly (and naturally  from the base class it’s declared in).</li>
<li><strong>C# provides a default constructor for me. I write a constructor that  takes a string as a parameter, but want to keep the no parameter one. How many  constructors should I write? </strong><br />
Two. Once you write at least one constructor,  C# cancels the freebie constructor, and now you have to write one yourself, even  if there’s no implementation in it.</li>
<li><strong>What’s the top .NET class that everything is derived from? </strong><br />
System.Object.</li>
<li><strong>How’s method overriding different from overloading? </strong><br />
When overriding,  you change the method behavior for a derived class. Overloading simply involves  having a method with the same name within the class.</li>
<li><strong>What does the keyword virtual mean in the method definition? </strong><br />
The  method can be over-ridden.</li>
<li><strong>Can you declare the override method static while the original method is  non-static? </strong><br />
No, you can’t, the signature of the virtual method must remain  the same, only the keyword virtual is changed to keyword override.</li>
<li><strong>Can you override private virtual methods? </strong><br />
No, moreover, you cannot  access private methods in inherited classes, have to be protected in the base  class to allow any sort of access.</li>
<li><strong>Can you prevent your class from being inherited and becoming a base class  for some other classes?</strong><br />
 Yes, that’s what keyword sealed in the class  definition is for. The developer trying to derive from your class will get a  message: cannot inherit from Sealed class WhateverBaseClassName. It’s the same  concept as final class in Java.</li>
<li><strong>Can you allow class to be inherited, but prevent the method from being  over-ridden? </strong><br />
Yes, just leave the class public and make the method  sealed.</li>
<li><strong>What’s an abstract class? </strong><br />
A class that cannot be instantiated. A  concept in C++ known as pure virtual method. A class that must be inherited and  have the methods over-ridden. Essentially, it’s a blueprint for a class without  any implementation.</li>
<li><strong>When do you absolutely have to declare a class as abstract (as opposed to  free-willed educated choice or decision based on UML diagram)? </strong><br />
When at least  one of the methods in the class is abstract. When the class itself is inherited  from an abstract class, but not all base abstract methods have been  over-ridden.</li>
<li><strong>What’s an interface class? </strong>It’s an abstract class with public abstract methods all of which must be implemented in the inherited classes.</li>
<li><strong>Why can’t you specify the accessibility modifier for methods inside the  interface? </strong><br />
They all must be public. Therefore, to prevent you from getting  the false impression that you have any freedom of choice, you are not allowed to  specify any accessibility, it’s public by default.</li>
<li><strong>Can you inherit multiple interfaces? </strong><br />
Yes, why not.</li>
<li><strong>And if they have conflicting method names? </strong><br />
It’s up to you to  implement the method inside your own class, so implementation is left entirely  up to you. This might cause a problem on a higher-level scale if similarly named  methods from different interfaces expect different data, but as far as compiler cares you’re okay.</li>
<li><strong>What’s the difference between an interface and abstract class? </strong><br />
In the  interface all methods must be abstract, in the abstract class some methods can  be concrete. In the interface no accessibility modifiers are allowed, which is  ok in abstract classes.</li>
<li><strong>How can you overload a method? </strong><br />
Different parameter data types,  different number of parameters, different order of parameters.</li>
<li><strong>If a base class has a bunch of overloaded constructors, and an inherited  class has another bunch of overloaded constructors, can you enforce a call from  an inherited constructor to an arbitrary base constructor? </strong><br />
Yes, just place a  colon, and then keyword base (parameter list to invoke the appropriate  constructor) in the overloaded constructor definition inside the inherited  class.</li>
<li><strong>What’s the difference between System.String and System.StringBuilder  classes? </strong><br />
System.String is immutable, System.StringBuilder was designed with  the purpose of having a mutable string where a variety of operations can be  performed.</li>
<li><strong>Is it namespace class or class namespace?</strong><br />
 The .NET class library is  organized into namespaces. Each namespace contains a functionally related group  of classes so natural namespace comes first.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.toars.com/2010/11/c-sharp-questions-and-answers-08/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# Questions and Answers &#8211; 07</title>
		<link>http://www.toars.com/2010/11/c-sharp-questions-and-answers-07/</link>
		<comments>http://www.toars.com/2010/11/c-sharp-questions-and-answers-07/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 11:21:29 +0000</pubDate>
		<dc:creator>Xin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Interviews]]></category>

		<guid isPermaLink="false">http://www.toars.com/?p=443</guid>
		<description><![CDATA[Are private class-level variables inherited? Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are. Why does DllImport not work for me? All methods marked with the DllImport attribute must be marked as public static extern. Why does my Windows application pop up [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li><strong>Are private class-level variables inherited? </strong><br />
Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.</li>
<li><strong>Why does DllImport not work for me? </strong><br />
All methods marked with the DllImport attribute must be marked as public static extern.</li>
<li><strong>Why does my Windows application pop up a console window every time I run it? </strong><br />
Make sure that the target type set in the project properties setting is set to Windows Application, and not Console Application. If you’re using the command line, compile with /target:winexe, not /target:exe.</li>
<li><strong>Why do I get an error (CS1006) when trying to declare a method without specifying a return type? </strong><br />
If you leave off the return type on a method declaration, the compiler thinks you are trying to declare a constructor. So if you are trying to declare a method that returns nothing, use void. The following is an example: // This results in a CS1006 error public static staticMethod (mainStatic obj) // This will work as wanted public static void staticMethod (mainStatic obj)</li>
<li><strong>Why do I get a syntax error when trying to declare a variable called checked? </strong><br />
The word checked is a keyword in C#.</li>
<li><strong>Why do I get a security exception when I try to run my C# app? </strong><br />
Some security exceptions are thrown if you are working on a network share. There are some parts of the frameworks that will not run if being run off a share (roaming profile, mapped drives, etc.). To see if this is what’s happening, just move the executable over to your local drive and see if it runs without the exceptions. One of the common exceptions thrown under these conditions is System.Security.SecurityException. To get around this, you can change your security policy for the intranet zone, code group 1.2, (the zone that running off shared folders falls into) by using the caspol.exe tool.</li>
<li><strong>Why do I get a <em>CS5001: does not have an entry point defined</em> error when compiling? </strong><br />
The most common problem is that you used a lowercase ‘m’ when defining the Main method. The correct way to implement the entry point is as follows: class test { static void Main(string[] args) {} }</li>
<li><strong>What optimizations does the C# compiler perform when you use the /optimize+ compiler option? </strong><br />
The following is a response from a developer on the C# compiler team: We get rid of unused locals (i.e., locals that are never read, even if assigned). We get rid of unreachable code. We get rid of try-catch with an empty try. We get rid of try-finally with an empty try. We get rid of try-finally with an empty finally. We optimize branches over branches: gotoif A, lab1 goto lab2: lab1: turns into: gotoif !A, lab2 lab1: We optimize branches to ret, branches to next instruction, and branches to branches.</li>
<li><strong>What is the syntax for calling an overloaded constructor within a constructor (this() and constructorname() does not compile)? </strong><br />
The syntax for calling another constructor is as follows:</p>
<pre>class B
{
	B(int i)
	{
	}
} 

class C : B
{
	C() : base(5) // call base constructor B(5)
	{
	} 

	C(int i) : this() // call C()
	{
	} 

	public static void Main()
	{
	}
}</pre>
</li>
<li><strong>What is the equivalent to regsvr32 and regsvr32 /u a file in .NET development? </strong><br />
Try using RegAsm.exe. Search MSDN on <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrfassemblyregistrationtoolregasmexe.asp">Assembly Registration Tool</a>.</li>
<li><strong>What is the difference between a struct and a class in C#? </strong><br />
From language spec: The list of similarities between classes and structs is as follows. Longstructs can implement interfaces and can have the same kinds of members as classes. Structs differ from classes in several important ways; however, structs are value types rather than reference types, and inheritance is not supported for structs. Struct values are stored on the stack or in-line. Careful programmers can sometimes enhance performance through judicious use of structs. For example, the use of a struct rather than a class for a Point can make a large difference in the number of memory allocations performed at runtime. The program below creates and initializes an array of 100 points. With Point implemented as a class, 101 separate objects are instantiated-one for the array and one each for the 100 elements.</li>
<li><strong>My switch statement works differently than in C++! Why? </strong><br />
C# does not support an explicit fall through for case blocks. The following code is not legal and will not compile in C#:</p>
<pre>switch(x)
{
	case 0: // do something
	case 1: // do something as continuation of case 0
	default: // do something in common with
		//0, 1 and everything else
	break;
}</pre>
<p>To achieve the same effect in C#, the code must be modified as shown below (notice how the control flows are explicit):</p>
<pre>class Test
{
	public static void Main() {
		int x = 3;
		switch(x)
		{
			case 0: // do something
			goto case 1;
			case 1: // do something in common with 0
			goto default;
			default: // do something in common with 0, 1, and anything else
			break;
		}
	}
}</pre>
</li>
<li><strong>Is there regular expression (regex) support available to C# developers? </strong><br />
Yes. The .NET class libraries provide support for regular expressions. Look at the <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemtextregularexpressions.asp">System.Text.RegularExpressions namespace</a>.</li>
<li><strong>Is there any sample C# code for simple threading? </strong><br />
Yes:</p>
<pre>using System;
using System.Threading;
class ThreadTest
{
	public void runme()
	{
		Console.WriteLine("Runme Called");
	}
	public static void Main(String[] args)
	{
		ThreadTest b = new ThreadTest();
		Thread t = new Thread(new ThreadStart(b.runme));
		t.Start();
	}
}</pre>
</li>
<li><strong>Is there an equivalent of exit() for quitting a C# .NET application? </strong><br />
Yes, you can use System.Environment.Exit(int exitCode) to exit the application or Application.Exit() if it’s a Windows Forms app.</li>
<li><strong>Is there a way to force garbage collection? </strong><br />
Yes. Set all references to null and then call System.GC.Collect(). If you need to have some objects destructed, and System.GC.Collect() doesn’t seem to be doing it for you, you can force finalizers to be run by setting all the references to the object to null and then calling System.GC.RunFinalizers().</li>
<li><strong>Is there a way of specifying which block or loop to break out of when working with nested loops? </strong><br />
The easiest way is to use goto:</p>
<pre>using System;
class BreakExample
{
	public static void Main(String[] args) {
		for(int i=0; i&lt;3; i++)
		{
			Console.WriteLine("Pass {0}: ", i);
			for( int j=0 ; j&lt;100 ; j++ )
			{
				if ( j == 10)
					goto done;
				Console.WriteLine("{0} ", j);
			}
			Console.WriteLine("This will not print");
		}
		done:
			Console.WriteLine("Loops complete.");
	}
}</pre>
</li>
<li><strong>Is it possible to restrict the scope of a field/method of a class to the classes in the same namespace? </strong><br />
There is no way to restrict to a namespace. Namespaces are never units of protection. But if you’re using assemblies, you can use the ‘internal’ access modifier to restrict access to only within the assembly.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.toars.com/2010/11/c-sharp-questions-and-answers-07/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

