<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>ProgramGood.Net - Events</title>
    <link>http://www.programgood.net/</link>
    <description>The journey to becoming a great programmer</description>
    <language>en-us</language>
    <copyright>Dave Mateer</copyright>
    <lastBuildDate>Wed, 04 Nov 2009 21:36:27 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.2.8279.16125</generator>
    <managingEditor>davemateer@gmail.com</managingEditor>
    <webMaster>davemateer@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=352f100b-df85-4ca2-aa5a-14d32e66ab1a</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,352f100b-df85-4ca2-aa5a-14d32e66ab1a.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <wfw:comment>http://www.programgood.net/CommentView,guid,352f100b-df85-4ca2-aa5a-14d32e66ab1a.aspx</wfw:comment>
      <wfw:commentRss>http://www.programgood.net/SyndicationService.asmx/GetEntryCommentsRss?guid=352f100b-df85-4ca2-aa5a-14d32e66ab1a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I know I've skipped a few chapters.. but
hey.. who is perfect?  Sometimes, it is good to get to some concrete results
to give some pespective.<br /><br />
After months of playing with code (why do things always take longer than you think..?),
and having a blast, I've now forgotton everything I know about asp.net.  So time
to do some spikes.<br /><br />
Here is a super simple reminder of asp.net syntax and simple events:<br /><br />
Default.aspx (\code\tddBook\SimpleAspSpike)<br /><br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">&lt;%@
Page Language=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"C#"</span> AutoEventWireup=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"true"</span> CodeBehind=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Default.aspx.cs"</span> Inherits=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"WebSite2testWebProj._Default"</span> %&gt;
&lt;!DOCTYPE html PUBLIC <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"-//W3C//DTD
XHTML 1.0 Transitional//EN"</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span>&gt;
&lt;html xmlns=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"http://www.w3.org/1999/xhtml"</span>&gt;
&lt;head id=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Head1"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span>&gt;
&lt;title&gt;Untitled Page&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"form2"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span>&gt;
&lt;div&gt; hello world from html&lt;br /&gt; &lt;%= <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Hello
from asp.net"</span> %&gt; &lt;br /&gt; This <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">is</span> a
label: &lt;asp:Label ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"label1"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> /&gt;
&lt;br /&gt; The time <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">is</span>:
&lt;%= System.DateTime.Now.ToLongTimeString()%&gt; &lt;br /&gt; This <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">is</span> a
textbox: &lt;asp:TextBox runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"textbox1"</span> /&gt;&lt;br
/&gt; A button: &lt;asp:Button runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"button1"</span> Text=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"press
me"</span> onclick=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"button1_Click"</span> /&gt;&lt;br
/&gt; Label2 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">is</span> here:
&lt;asp:Label ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"label2"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> /&gt;&lt;br
/&gt; asp.net uses viewstate.. so the button <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">is</span> just
a submit button, which then goes back to the server, refreshes the page with the <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">new</span> data <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">in</span> the
label2 label. &lt;br /&gt; &lt;/div&gt; Autopostback <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">is</span> set <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">in</span> the
following DropDownList (server control)... makes contact with the server each time
an item <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">is</span> selected..
which we can use to wire up an <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">event</span>..onselectedindexchanged&lt;br
/&gt; &lt;asp:DropDownList runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"GreetList"</span> AutoPostBack=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"true"</span> onselectedindexchanged=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"GreetList_SelectedIndexChanged"</span>&gt;
&lt;asp:ListItem Value=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"no
one"</span>&gt;No one&lt;/asp:ListItem&gt; &lt;asp:ListItem Value=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"world"</span>&gt;World&lt;/asp:ListItem&gt;
&lt;asp:ListItem Value=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"universe"</span>&gt;Universe&lt;/asp:ListItem&gt;
&lt;/asp:DropDownList&gt;&lt;br /&gt; Label3: &lt;asp:Label ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"label3"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> /&gt;
&lt;br /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</span></pre><br />
And the Default.aspx.cs<br /><br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">using</span> System; <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">using</span> System.Web.UI; <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">namespace</span> WebSite2testWebProj
{ <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">public</span> partial <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">class</span> _Default
: Page { <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">protected</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">void</span> Page_Load(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">object</span> sender,
EventArgs e) { Response.Write(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Hello
from Page_Load in codebehind"</span>); label1.Text <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Hello
from the codebehind into a label"</span>; textbox1.Text <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Textbox
from codebehind"</span>; } <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">protected</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">void</span> button1_Click(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">object</span> sender,
EventArgs e) { label2.Text <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"button
pressed"</span>; } <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">protected</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">void</span> GreetList_SelectedIndexChanged(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">object</span> sender,
EventArgs e) { label3.Text <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Hello,
"</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">+</span> GreetList.SelectedValue;
} } }</span></pre><br />
Ok, looking good so far.<br /><br />
Difference between <b>CodeBehind and CodeFile</b><br /><br /><b>WebSite or Web Application Project?</b><br />
http://www.dotnetspider.com/resources/1520-Difference-between-web-site-web-application.aspx<br /><br />
WebSite is really simple, with no project file.  Web Application Project has
a project file.<br /><br />
Found that remembering how to access databases isn't too easy:<br /><br />
looking at old project:<br />
http://treasuresprint.blogspot.com<br /><br />
Realised I didn't put up the sourcecode at the time, and have managed to find it on
my laptop:<br /><br /><br /><b>Connecting to and displaying data from a DB very easily:</b><br /><br />
Deafult.aspx (\code\tddBook\DBConnectySpike)<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">&lt;form
id=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"form1"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span>&gt;
&lt;div&gt; &lt;asp:SqlDataSource ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"SqlDataSource1"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> ConnectionString=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"&lt;%$
ConnectionStrings:TreasureConnectionString %&gt;"</span> SelectCommand=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"SELECT
[StuffId], [Description] FROM [Stuff]"</span>&gt;&lt;/asp:SqlDataSource&gt; &lt;br
/&gt; &lt;br /&gt; <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">is</span> a
gridview&amp;nbsp;&lt;asp:GridView ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"GridView1"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> AutoGenerateColumns=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"False"</span> DataKeyNames=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"StuffId"</span> DataSourceID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"SqlDataSource1"</span>&gt;
&lt;Columns&gt; &lt;asp:BoundField DataField=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"StuffId"</span> HeaderText=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"StuffId"</span> InsertVisible=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"False"</span> ReadOnly=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"True"</span> SortExpression=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"StuffId"</span> /&gt;
&lt;asp:BoundField DataField=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Description"</span> HeaderText=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Description"</span> SortExpression=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Description"</span> /&gt;
&lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;br /&gt; <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">is</span> a
datalist&lt;br /&gt; &lt;br /&gt; &lt;asp:DataList ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"DataList1"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> DataSourceID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"SqlDataSource1"</span> &gt;
&lt;ItemTemplate&gt; &lt;asp:Literal ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Literal2"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> Text=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Description:"</span>&gt;&lt;/asp:Literal&gt;
&lt;asp:Literal ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Literal1"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> Text='&lt;%#
Eval(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Description"</span>)
%&gt;'&gt;&lt;/asp:Literal&gt; &lt;/ItemTemplate&gt; &lt;EditItemTemplate&gt; &lt;asp:Literal
ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Literal2"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> Text=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Description:"</span>&gt;&lt;/asp:Literal&gt;
&lt;asp:TextBox ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"TextBox1"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> Text='&lt;%#
Eval(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Description"</span>)
%&gt;' Width=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"208px"</span>&gt;&lt;/asp:TextBox&gt;
&lt;/EditItemTemplate&gt; &lt;/asp:DataList&gt;&lt;br /&gt; &lt;br /&gt; <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">is</span> a
details view&lt;/div&gt; &lt;asp:DetailsView ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"DetailsView1"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> AutoGenerateRows=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"False"</span> CellPadding=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"4"</span> DataKeyNames=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"StuffId"</span> DataSourceID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"SqlDataSource1"</span> ForeColor=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#333333"</span> GridLines=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"None"</span> Height=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"50px"</span> Width=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"341px"</span>&gt;
&lt;FooterStyle BackColor=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#507CD1"</span> Font-Bold=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"True"</span> ForeColor=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"White"</span> /&gt;
&lt;CommandRowStyle BackColor=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#D1DDF1"</span> Font-Bold=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"True"</span> /&gt;
&lt;EditRowStyle BackColor=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#2461BF"</span> /&gt;
&lt;RowStyle BackColor=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#EFF3FB"</span> /&gt;
&lt;PagerStyle BackColor=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#2461BF"</span> ForeColor=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"White"</span> HorizontalAlign=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Center"</span> /&gt;
&lt;Fields&gt; &lt;asp:BoundField DataField=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"StuffId"</span> HeaderText=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"StuffId"</span> InsertVisible=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"False"</span> ReadOnly=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"True"</span> SortExpression=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"StuffId"</span> /&gt;
&lt;asp:BoundField DataField=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Description"</span> HeaderText=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Description"</span> SortExpression=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Description"</span> /&gt;
&lt;/Fields&gt; &lt;FieldHeaderStyle BackColor=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#DEE8F5"</span> Font-Bold=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"True"</span> /&gt;
&lt;HeaderStyle BackColor=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"#507CD1"</span> Font-Bold=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"True"</span> ForeColor=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"White"</span> /&gt;
&lt;AlternatingRowStyle BackColor=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"White"</span> /&gt;
&lt;/asp:DetailsView&gt; &lt;br /&gt; &lt;br /&gt; &lt;/form&gt;</span></pre>And in
the web.config:<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">&lt;connectionStrings&gt;
&lt;add name=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"TreasureConnectionString"</span> connectionString=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Data
Source=localhost;Initial Catalog=Treasure;Persist Security Info=True;User ID=dave;Password=letmein"</span> providerName=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"System.Data.SqlClient"</span>/&gt;
    &lt;/connectionStrings&gt;</span></pre>So it should come out
like this:<br /><br /><p></p><img src="http://www.programgood.net/content/binary/screen123456789101112131415.gif" border="0" /><br /><b>Thoughts</b><br />
ASP.NET offers some controls to make life 'easier' such as databinding, edit, deleting,
sorting on the gridview:  All pretty powerful for RAD, however for testable apps..
am not sure this is the way.  Or perhaps other Grid controls like Telerik are
better.  Maybe best to Keep it Simple.<br /><br />
Ideally we want testable code, with a thin layer of UI code on top.<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">A
gridview with update &lt;asp:SqlDataSource ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"SqlDataSource2"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> ConnectionString=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"&lt;%$
ConnectionStrings:TreasureConnectionString %&gt;"</span> SelectCommand=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"SELECT
[StuffId], [Description] FROM [Stuff]"</span> UpdateCommand=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"UPDATE
Stuff SET Description=@Description WHERE StuffID=@StuffID"</span>&gt; &lt;/asp:SqlDataSource&gt;
&lt;asp:GridView ID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"GridView2"</span> runat=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"server"</span> AutoGenerateColumns=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"False"</span> DataKeyNames=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"StuffId"</span> AutoGenerateEditButton=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"true"</span> DataSourceID=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"SqlDataSource2"</span>&gt;
&lt;Columns&gt; &lt;asp:BoundField DataField=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"StuffId"</span> HeaderText=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"StuffId"</span>/&gt;
&lt;asp:BoundField DataField=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Description"</span> HeaderText=<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Description"</span>/&gt;
&lt;/Columns&gt; &lt;/asp:GridView&gt;</span></pre><img src="http://www.programgood.net/content/binary/screen12345678910111213141516.gif" border="0" /><br /><br />
And DropDownList / TextBox common usage:<br /><br /><br /><img src="http://www.programgood.net/content/binary/screen1234567891011121314151617.gif" border="0" /><br /><br />
This is all in the DB spike source code here:<br /><a href="http://www.programgood.net/content/binary/DBConnectSpike.zip">DBConnectSpike.zip
(15.17 KB)</a><br /><br />
Data Control Summary<br />
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/default.aspx<br /><br />
Gridview - the classic Grid..edit, delete, sort, page.  Takes advantage of DataSource
controls<br />
DataList - items in a repeating list<br />
DetailsView - typically used.. if a gridview item is selected, the detailsView is
displayed to edit.<br />
FormView - same as above but with no built in template.<br />
Repeater - has no built in layout or styles.  No column layout. No Edit/Del<br /><br />
Going through the SearchPage.aspx.. trying to get any of this application to compile. 
Have got source from book.. however..  good practise to chop code and and try
and work through.  Hmm - sometimes better to revert back to compiling code in
source control.<br /><br />
This project is in need of refactoring... too complex currently.  Would like
to 'defactor' for simplicity, then put some patterns back in.  Webservice would
be first to go, and use POCOs.  XSD definition for DTOs would go as well, with
simple objects as definitions.  DAL I'd like to take out Datasets and use a manual
DAL.<br /><br />
Most important thing is to get it working.  Good thing about this project so
far, is that it is testable at every level.<br /><img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=352f100b-df85-4ca2-aa5a-14d32e66ab1a" /></body>
      <title>ASP.NET Web Client Front End - Ch12</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,352f100b-df85-4ca2-aa5a-14d32e66ab1a.aspx</guid>
      <link>http://www.programgood.net/2009/11/04/ASPNETWebClientFrontEndCh12.aspx</link>
      <pubDate>Wed, 04 Nov 2009 21:36:27 GMT</pubDate>
      <description>I know I've skipped a few chapters.. but hey.. who is perfect?&amp;nbsp;
Sometimes, it is good to get to some concrete results to give some
pespective.&lt;br&gt;
&lt;br&gt;
After months of playing with code (why do things always take longer than you think..?),
and having a blast, I've now forgotton everything I know about asp.net.&amp;nbsp; So time
to do some spikes.&lt;br&gt;
&lt;br&gt;
Here is a super simple reminder of asp.net syntax and simple events:&lt;br&gt;
&lt;br&gt;
Default.aspx (\code\tddBook\SimpleAspSpike)&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;lt;%@
Page Language=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"C#"&lt;/span&gt; AutoEventWireup=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"true"&lt;/span&gt; CodeBehind=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Default.aspx.cs"&lt;/span&gt; Inherits=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"WebSite2testWebProj._Default"&lt;/span&gt; %&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"-//W3C//DTD
XHTML 1.0 Transitional//EN"&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/span&gt;&amp;gt;
&amp;lt;html xmlns=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"http://www.w3.org/1999/xhtml"&lt;/span&gt;&amp;gt;
&amp;lt;head id=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Head1"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt;&amp;gt;
&amp;lt;title&amp;gt;Untitled Page&amp;lt;/title&amp;gt; &amp;lt;/head&amp;gt; &amp;lt;body&amp;gt; &amp;lt;form id=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"form2"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt;&amp;gt;
&amp;lt;div&amp;gt; hello world from html&amp;lt;br /&amp;gt; &amp;lt;%= &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Hello
from asp.net"&lt;/span&gt; %&amp;gt; &amp;lt;br /&amp;gt; This &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt; a
label: &amp;lt;asp:Label ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"label1"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; /&amp;gt;
&amp;lt;br /&amp;gt; The time &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt;:
&amp;lt;%= System.DateTime.Now.ToLongTimeString()%&amp;gt; &amp;lt;br /&amp;gt; This &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt; a
textbox: &amp;lt;asp:TextBox runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"textbox1"&lt;/span&gt; /&amp;gt;&amp;lt;br
/&amp;gt; A button: &amp;lt;asp:Button runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"button1"&lt;/span&gt; Text=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"press
me"&lt;/span&gt; onclick=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"button1_Click"&lt;/span&gt; /&amp;gt;&amp;lt;br
/&amp;gt; Label2 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt; here:
&amp;lt;asp:Label ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"label2"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; /&amp;gt;&amp;lt;br
/&amp;gt; asp.net uses viewstate.. so the button &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt; just
a submit button, which then goes back to the server, refreshes the page with the &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; data &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;in&lt;/span&gt; the
label2 label. &amp;lt;br /&amp;gt; &amp;lt;/div&amp;gt; Autopostback &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt; set &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;in&lt;/span&gt; the
following DropDownList (server control)... makes contact with the server each time
an item &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt; selected..
which we can use to wire up an &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;event&lt;/span&gt;..onselectedindexchanged&amp;lt;br
/&amp;gt; &amp;lt;asp:DropDownList runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"GreetList"&lt;/span&gt; AutoPostBack=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"true"&lt;/span&gt; onselectedindexchanged=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"GreetList_SelectedIndexChanged"&lt;/span&gt;&amp;gt;
&amp;lt;asp:ListItem Value=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"no
one"&lt;/span&gt;&amp;gt;No one&amp;lt;/asp:ListItem&amp;gt; &amp;lt;asp:ListItem Value=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"world"&lt;/span&gt;&amp;gt;World&amp;lt;/asp:ListItem&amp;gt;
&amp;lt;asp:ListItem Value=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"universe"&lt;/span&gt;&amp;gt;Universe&amp;lt;/asp:ListItem&amp;gt;
&amp;lt;/asp:DropDownList&amp;gt;&amp;lt;br /&amp;gt; Label3: &amp;lt;asp:Label ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"label3"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; /&amp;gt;
&amp;lt;br /&amp;gt; &amp;lt;/form&amp;gt; &amp;lt;/body&amp;gt; &amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
And the Default.aspx.cs&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; System; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; System.Web.UI; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;namespace&lt;/span&gt; WebSite2testWebProj
{ &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; partial &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;class&lt;/span&gt; _Default
: Page { &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;protected&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; Page_Load(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;object&lt;/span&gt; sender,
EventArgs e) { Response.Write(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Hello
from Page_Load in codebehind"&lt;/span&gt;); label1.Text &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Hello
from the codebehind into a label"&lt;/span&gt;; textbox1.Text &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Textbox
from codebehind"&lt;/span&gt;; } &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;protected&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; button1_Click(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;object&lt;/span&gt; sender,
EventArgs e) { label2.Text &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"button
pressed"&lt;/span&gt;; } &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;protected&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; GreetList_SelectedIndexChanged(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;object&lt;/span&gt; sender,
EventArgs e) { label3.Text &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Hello,
"&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; GreetList.SelectedValue;
} } }&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
Ok, looking good so far.&lt;br&gt;
&lt;br&gt;
Difference between &lt;b&gt;CodeBehind and CodeFile&lt;/b&gt;
&lt;br&gt;
&lt;br&gt;
&lt;b&gt;WebSite or Web Application Project?&lt;/b&gt;
&lt;br&gt;
http://www.dotnetspider.com/resources/1520-Difference-between-web-site-web-application.aspx&lt;br&gt;
&lt;br&gt;
WebSite is really simple, with no project file.&amp;nbsp; Web Application Project has
a project file.&lt;br&gt;
&lt;br&gt;
Found that remembering how to access databases isn't too easy:&lt;br&gt;
&lt;br&gt;
looking at old project:&lt;br&gt;
http://treasuresprint.blogspot.com&lt;br&gt;
&lt;br&gt;
Realised I didn't put up the sourcecode at the time, and have managed to find it on
my laptop:&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;b&gt;Connecting to and displaying data from a DB very easily:&lt;/b&gt;
&lt;br&gt;
&lt;br&gt;
Deafult.aspx (\code\tddBook\DBConnectySpike)&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;lt;form
id=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"form1"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt;&amp;gt;
&amp;lt;div&amp;gt; &amp;lt;asp:SqlDataSource ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"SqlDataSource1"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; ConnectionString=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"&amp;lt;%$
ConnectionStrings:TreasureConnectionString %&amp;gt;"&lt;/span&gt; SelectCommand=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"SELECT
[StuffId], [Description] FROM [Stuff]"&lt;/span&gt;&amp;gt;&amp;lt;/asp:SqlDataSource&amp;gt; &amp;lt;br
/&amp;gt; &amp;lt;br /&amp;gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt; a
gridview&amp;amp;nbsp;&amp;lt;asp:GridView ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"GridView1"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; AutoGenerateColumns=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"False"&lt;/span&gt; DataKeyNames=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"StuffId"&lt;/span&gt; DataSourceID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"SqlDataSource1"&lt;/span&gt;&amp;gt;
&amp;lt;Columns&amp;gt; &amp;lt;asp:BoundField DataField=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"StuffId"&lt;/span&gt; HeaderText=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"StuffId"&lt;/span&gt; InsertVisible=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"False"&lt;/span&gt; ReadOnly=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"True"&lt;/span&gt; SortExpression=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"StuffId"&lt;/span&gt; /&amp;gt;
&amp;lt;asp:BoundField DataField=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Description"&lt;/span&gt; HeaderText=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Description"&lt;/span&gt; SortExpression=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Description"&lt;/span&gt; /&amp;gt;
&amp;lt;/Columns&amp;gt; &amp;lt;/asp:GridView&amp;gt; &amp;lt;br /&amp;gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt; a
datalist&amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; &amp;lt;asp:DataList ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"DataList1"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; DataSourceID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"SqlDataSource1"&lt;/span&gt; &amp;gt;
&amp;lt;ItemTemplate&amp;gt; &amp;lt;asp:Literal ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Literal2"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; Text=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Description:"&lt;/span&gt;&amp;gt;&amp;lt;/asp:Literal&amp;gt;
&amp;lt;asp:Literal ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Literal1"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; Text='&amp;lt;%#
Eval(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Description"&lt;/span&gt;)
%&amp;gt;'&amp;gt;&amp;lt;/asp:Literal&amp;gt; &amp;lt;/ItemTemplate&amp;gt; &amp;lt;EditItemTemplate&amp;gt; &amp;lt;asp:Literal
ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Literal2"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; Text=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Description:"&lt;/span&gt;&amp;gt;&amp;lt;/asp:Literal&amp;gt;
&amp;lt;asp:TextBox ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"TextBox1"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; Text='&amp;lt;%#
Eval(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Description"&lt;/span&gt;)
%&amp;gt;' Width=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"208px"&lt;/span&gt;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;
&amp;lt;/EditItemTemplate&amp;gt; &amp;lt;/asp:DataList&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt; a
details view&amp;lt;/div&amp;gt; &amp;lt;asp:DetailsView ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"DetailsView1"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; AutoGenerateRows=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"False"&lt;/span&gt; CellPadding=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"4"&lt;/span&gt; DataKeyNames=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"StuffId"&lt;/span&gt; DataSourceID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"SqlDataSource1"&lt;/span&gt; ForeColor=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"#333333"&lt;/span&gt; GridLines=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"None"&lt;/span&gt; Height=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"50px"&lt;/span&gt; Width=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"341px"&lt;/span&gt;&amp;gt;
&amp;lt;FooterStyle BackColor=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"#507CD1"&lt;/span&gt; Font-Bold=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"True"&lt;/span&gt; ForeColor=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"White"&lt;/span&gt; /&amp;gt;
&amp;lt;CommandRowStyle BackColor=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"#D1DDF1"&lt;/span&gt; Font-Bold=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"True"&lt;/span&gt; /&amp;gt;
&amp;lt;EditRowStyle BackColor=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"#2461BF"&lt;/span&gt; /&amp;gt;
&amp;lt;RowStyle BackColor=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"#EFF3FB"&lt;/span&gt; /&amp;gt;
&amp;lt;PagerStyle BackColor=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"#2461BF"&lt;/span&gt; ForeColor=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"White"&lt;/span&gt; HorizontalAlign=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Center"&lt;/span&gt; /&amp;gt;
&amp;lt;Fields&amp;gt; &amp;lt;asp:BoundField DataField=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"StuffId"&lt;/span&gt; HeaderText=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"StuffId"&lt;/span&gt; InsertVisible=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"False"&lt;/span&gt; ReadOnly=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"True"&lt;/span&gt; SortExpression=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"StuffId"&lt;/span&gt; /&amp;gt;
&amp;lt;asp:BoundField DataField=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Description"&lt;/span&gt; HeaderText=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Description"&lt;/span&gt; SortExpression=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Description"&lt;/span&gt; /&amp;gt;
&amp;lt;/Fields&amp;gt; &amp;lt;FieldHeaderStyle BackColor=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"#DEE8F5"&lt;/span&gt; Font-Bold=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"True"&lt;/span&gt; /&amp;gt;
&amp;lt;HeaderStyle BackColor=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"#507CD1"&lt;/span&gt; Font-Bold=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"True"&lt;/span&gt; ForeColor=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"White"&lt;/span&gt; /&amp;gt;
&amp;lt;AlternatingRowStyle BackColor=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"White"&lt;/span&gt; /&amp;gt;
&amp;lt;/asp:DetailsView&amp;gt; &amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; &amp;lt;/form&amp;gt;&lt;/span&gt;&lt;/pre&gt;And in
the web.config:&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;lt;connectionStrings&amp;gt;
&amp;lt;add name=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"TreasureConnectionString"&lt;/span&gt; connectionString=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Data
Source=localhost;Initial Catalog=Treasure;Persist Security Info=True;User ID=dave;Password=letmein"&lt;/span&gt; providerName=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"System.Data.SqlClient"&lt;/span&gt;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/connectionStrings&amp;gt;&lt;/span&gt;&lt;/pre&gt;So it should come out
like this:&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img src="http://www.programgood.net/content/binary/screen123456789101112131415.gif" border="0"&gt;
&lt;br&gt;
&lt;b&gt;Thoughts&lt;/b&gt;
&lt;br&gt;
ASP.NET offers some controls to make life 'easier' such as databinding, edit, deleting,
sorting on the gridview:&amp;nbsp; All pretty powerful for RAD, however for testable apps..
am not sure this is the way.&amp;nbsp; Or perhaps other Grid controls like Telerik are
better.&amp;nbsp; Maybe best to Keep it Simple.&lt;br&gt;
&lt;br&gt;
Ideally we want testable code, with a thin layer of UI code on top.&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;A
gridview with update &amp;lt;asp:SqlDataSource ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"SqlDataSource2"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; ConnectionString=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"&amp;lt;%$
ConnectionStrings:TreasureConnectionString %&amp;gt;"&lt;/span&gt; SelectCommand=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"SELECT
[StuffId], [Description] FROM [Stuff]"&lt;/span&gt; UpdateCommand=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"UPDATE
Stuff SET Description=@Description WHERE StuffID=@StuffID"&lt;/span&gt;&amp;gt; &amp;lt;/asp:SqlDataSource&amp;gt;
&amp;lt;asp:GridView ID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"GridView2"&lt;/span&gt; runat=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"server"&lt;/span&gt; AutoGenerateColumns=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"False"&lt;/span&gt; DataKeyNames=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"StuffId"&lt;/span&gt; AutoGenerateEditButton=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"true"&lt;/span&gt; DataSourceID=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"SqlDataSource2"&lt;/span&gt;&amp;gt;
&amp;lt;Columns&amp;gt; &amp;lt;asp:BoundField DataField=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"StuffId"&lt;/span&gt; HeaderText=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"StuffId"&lt;/span&gt;/&amp;gt;
&amp;lt;asp:BoundField DataField=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Description"&lt;/span&gt; HeaderText=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Description"&lt;/span&gt;/&amp;gt;
&amp;lt;/Columns&amp;gt; &amp;lt;/asp:GridView&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;img src="http://www.programgood.net/content/binary/screen12345678910111213141516.gif" border="0"&gt;
&lt;br&gt;
&lt;br&gt;
And DropDownList / TextBox common usage:&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;img src="http://www.programgood.net/content/binary/screen1234567891011121314151617.gif" border="0"&gt;
&lt;br&gt;
&lt;br&gt;
This is all in the DB spike source code here:&lt;br&gt;
&lt;a href="http://www.programgood.net/content/binary/DBConnectSpike.zip"&gt;DBConnectSpike.zip
(15.17 KB)&lt;/a&gt;
&lt;br&gt;
&lt;br&gt;
Data Control Summary&lt;br&gt;
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/default.aspx&lt;br&gt;
&lt;br&gt;
Gridview - the classic Grid..edit, delete, sort, page.&amp;nbsp; Takes advantage of DataSource
controls&lt;br&gt;
DataList - items in a repeating list&lt;br&gt;
DetailsView - typically used.. if a gridview item is selected, the detailsView is
displayed to edit.&lt;br&gt;
FormView - same as above but with no built in template.&lt;br&gt;
Repeater - has no built in layout or styles.&amp;nbsp; No column layout. No Edit/Del&lt;br&gt;
&lt;br&gt;
Going through the SearchPage.aspx.. trying to get any of this application to compile.&amp;nbsp;
Have got source from book.. however..&amp;nbsp; good practise to chop code and and try
and work through.&amp;nbsp; Hmm - sometimes better to revert back to compiling code in
source control.&lt;br&gt;
&lt;br&gt;
This project is in need of refactoring... too complex currently.&amp;nbsp; Would like
to 'defactor' for simplicity, then put some patterns back in.&amp;nbsp; Webservice would
be first to go, and use POCOs.&amp;nbsp; XSD definition for DTOs would go as well, with
simple objects as definitions.&amp;nbsp; DAL I'd like to take out Datasets and use a manual
DAL.&lt;br&gt;
&lt;br&gt;
Most important thing is to get it working.&amp;nbsp; Good thing about this project so
far, is that it is testable at every level.&lt;br&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=352f100b-df85-4ca2-aa5a-14d32e66ab1a" /&gt;</description>
      <comments>http://www.programgood.net/CommentView,guid,352f100b-df85-4ca2-aa5a-14d32e66ab1a.aspx</comments>
      <category>ASP.NET Best Practise</category>
      <category>Events</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=fd2843fb-2372-4c78-bf60-4269cf0468cd</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,fd2843fb-2372-4c78-bf60-4269cf0468cd.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <wfw:comment>http://www.programgood.net/CommentView,guid,fd2843fb-2372-4c78-bf60-4269cf0468cd.aspx</wfw:comment>
      <wfw:commentRss>http://www.programgood.net/SyndicationService.asmx/GetEntryCommentsRss?guid=fd2843fb-2372-4c78-bf60-4269cf0468cd</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <img src="http://www.programgood.net/content/binary/matrix.jpg" border="0" />
        <br />
        <br />
Thanks to the original author of the code (google m7tr1x).. 
<br /><br />
I had some great fun looking at the code, understanding how this effect works, and
refactoring.<br /><br />
The original code is below.. I suggest scrolling down, and looking at the refactored
code and pictures describing how the effect works.<br /><br />
Enjoy!<br /><br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">#define</span> readkey <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">using</span> System; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">namespace</span> m7tr1x
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">class</span> Program
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">void</span> Main(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span>[
] args) { Console.Title <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"tH3
M7tr1x 3ff3&lt;t"</span>; Console.ForegroundColor <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> ConsoleColor.DarkGreen;
Console.WindowLeft <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Console.WindowTop <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> 0;
Console.WindowHeight <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Console.BufferHeight <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Console.LargestWindowHeight;
Console.WindowWidth <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Console.BufferWidth <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Console.LargestWindowWidth; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">#if</span> readkey
Console.WriteLine(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"H1T
7NY K3Y T0 C0NT1NU3 =/"</span>); Console.ReadKey(); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">#endif</span> Console.CursorVisible <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">false</span>; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> width,
height; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>[
] y; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>[
] l; Initialize(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span> width, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span> height, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span> y, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span> l); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> ms; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">while</span> ( <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">true</span> )
{ DateTime t1 <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> DateTime.Now;
MatrixStep(width, height, y, l); ms <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> 10 <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">-</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>)(
(TimeSpan)( DateTime.Now <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">-</span> t1
) ).TotalMilliseconds; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (
ms &gt; 0 ) System.Threading.Thread.Sleep(ms); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (
Console.KeyAvailable ) <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (
Console.ReadKey().Key == ConsoleKey.F5 ) Initialize(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span> width, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span> height, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span> y, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span> l);
} } <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">bool</span> thistime <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">false</span>; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">private</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">void</span> MatrixStep(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> width, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> height, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>[
] y, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>[
] l) { <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> x;
thistime <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> !thistime; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">for</span> (
x <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> 0
; x &lt; width ; ++x ) { <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (
x <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">%</span> 11
== 10 ) { <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (
!thistime ) <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">continue</span>;
Console.ForegroundColor <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> ConsoleColor.White;
} <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">else</span> {
Console.ForegroundColor <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> ConsoleColor.DarkGreen;
Console.SetCursorPosition(x, inBoxY(y[x] <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">-</span> 2 <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">-</span> (
l[x] <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">/</span> 40 <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">*</span> 2
), height)); Console.Write(R); Console.ForegroundColor <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> ConsoleColor.Green;
} Console.SetCursorPosition(x, y[x]); Console.Write(R); y[x] <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> inBoxY(y[x] <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span> 1,
height); Console.SetCursorPosition(x, inBoxY(y[x] <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">-</span> l[x],
height)); Console.Write(' '); } } <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">private</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">void</span> Initialize(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> width, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> height, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>[
] y, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>[
] l) { <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> h1; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> h2 <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> (
h1 <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> (
height <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Console.WindowHeight
) <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">/</span> 2
) <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">/</span> 2;
width <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Console.WindowWidth <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">-</span> 1;
y <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>[width];
l <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>[width]; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> x;
Console.Clear(); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">for</span> (
x <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> 0
; x &lt; width ; ++x ) { y[x] <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> r.Next(height);
l[x] <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> r.Next(h2 <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">*</span> (
( x <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">%</span> 11
!<span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> 10
) ? 2 : 1 ), h1 <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">*</span> (
( x <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">%</span> 11
!<span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> 10
) ? 2 : 1 )); } } <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span> Random
r <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> Random(); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">char</span> R
{ get { <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> t <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> r.Next(10); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (
t &lt;= 2 ) <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">char</span>)(
'0' <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span> r.Next(10)
); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">else</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (
t &lt;= 4 ) <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">char</span>)(
'a' <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span> r.Next(27)
); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">else</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (
t &lt;= 6 ) <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">char</span>)(
'A' <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span> r.Next(27)
); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">else</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">char</span>)(
r.Next(32, 255) ); } } <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> inBoxY(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> n, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> height)
{ n <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> n <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">%</span> height; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (
n &lt; 0 ) <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> n <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span> height; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">else</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> n;
} } }</span></pre>Here is the refactored code:<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">using</span> System; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">namespace</span> matrix
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">class</span> Program
{ <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
fields</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span> Random
rand <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> Random(); <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
properties</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">char</span> AsciiCharacter
{ get { <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> t <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> rand.Next(10); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (t
&lt;= 2) <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
returns a number</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">char</span>)('0' <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span> rand.Next(10)); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">else</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (t
&lt;= 4) <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
small letter</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">char</span>)('a' <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span> rand.Next(27)); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">else</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (t
&lt;= 6) <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
capital letter</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">char</span>)('A' <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span> rand.Next(27)); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">else</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
any ascii character</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">char</span>)(rand.Next(32,
255)); } } <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
methods</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">void</span> Main()
{ Console.ForegroundColor <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> ConsoleColor.DarkGreen;
Console.WindowLeft <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Console.WindowTop <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> 0;
Console.WindowHeight <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Console.BufferHeight <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Console.LargestWindowHeight;
Console.WindowWidth <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Console.BufferWidth <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Console.LargestWindowWidth;
Console.WriteLine(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Hit
Any Key To Continue"</span>); Console.ReadKey(); Console.CursorVisible <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">false</span>; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> width,
height; <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
setup array of starting y values</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>[]
y; <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
width was 209, height was 81</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
setup the screen and initial conditions of y</span> Initialize(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span> width, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span> height, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span> y); <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
do the Matrix effect</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
every loop all y's get incremented by 1</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">while</span> ( <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">true</span> )
UpdateAllColumns(width, height, y); } <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">private</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">void</span> UpdateAllColumns(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> width, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> height, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>[]
y) { <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> x; <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
draws 3 characters in each x column each time... </span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
a dark green, light green, and a space</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
y is the position on the screen</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
y[x] increments 1 each time so each loop does the same thing but down 1 y value</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">for</span> (
x <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> 0
; x &lt; width ; ++x ) { <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
the bright green character</span> Console.ForegroundColor <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> ConsoleColor.Green;
Console.SetCursorPosition(x, y[x]); Console.Write(AsciiCharacter); <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
the dark green character - 2 positions above the bright green character</span> Console.ForegroundColor <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> ConsoleColor.DarkGreen; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> temp <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> y[x] <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">-</span> 2;
Console.SetCursorPosition(x, inScreenYPosition(temp, height)); Console.Write(AsciiCharacter); <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
the 'space' - 20 positions above the bright green character</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> temp1 <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> y[x] <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">-</span> 20;
Console.SetCursorPosition(x, inScreenYPosition(temp1, height)); Console.Write(' '); <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
increment y</span> y[x] <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> inScreenYPosition(y[x] <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span> 1,
height); } <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
F5 to reset, F11 to pause and unpause</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (Console.KeyAvailable)
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (Console.ReadKey().Key
== ConsoleKey.F5) Initialize(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span> width, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span> height, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span> y); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (Console.ReadKey().Key
== ConsoleKey.F11) System.Threading.Thread.Sleep(1); } } <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
Deals with what happens when y position is off screen</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> inScreenYPosition(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> yPosition, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> height)
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (yPosition
&lt; 0) <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> yPosition <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span> height; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">else</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (yPosition
&lt; height) <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> yPosition; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">else</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> 0;
} <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
only called once at the start</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">private</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">void</span> Initialize(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> width, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> height, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">out</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>[]
y) { height <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Console.WindowHeight;
width <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Console.WindowWidth <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">-</span> 1; <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
209 for me.. starting y positions of bright green characters</span> y <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>[width];
Console.Clear(); <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
loops 209 times for me</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">for</span> ( <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> x <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> 0
; x &lt; width ; ++x ) { <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//
gets random number between 0 and 81</span> y[x] <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> rand.Next(height);
} } } }</span></pre><br /><p></p>
how it works:<br /><br />
The screen draws each column.. my screen is 208 wide.. so it loops 208 times, each
time drawing a bright green character, dark green character, and a space.<br /><br /><img src="http://www.programgood.net/content/binary/number1.jpg" border="0" /><br /><br />
The second loop.. the y value has been incremented by 1.<br /><br /><img src="http://www.programgood.net/content/binary/number2.jpg" border="0" /><br /><br />
The 3rd loop<br /><br /><img src="http://www.programgood.net/content/binary/number3.jpg" border="0" /><br /><br />
Enjoy!<br /><img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=fd2843fb-2372-4c78-bf60-4269cf0468cd" /></body>
      <title>Matrix Rain Effect in C# Console App</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,fd2843fb-2372-4c78-bf60-4269cf0468cd.aspx</guid>
      <link>http://www.programgood.net/2009/02/25/MatrixRainEffectInCConsoleApp.aspx</link>
      <pubDate>Wed, 25 Feb 2009 19:47:32 GMT</pubDate>
      <description>&lt;img src="http://www.programgood.net/content/binary/matrix.jpg" border="0"&gt;
&lt;br&gt;
&lt;br&gt;
Thanks to the original author of the code (google m7tr1x).. 
&lt;br&gt;
&lt;br&gt;
I had some great fun looking at the code, understanding how this effect works, and
refactoring.&lt;br&gt;
&lt;br&gt;
The original code is below.. I suggest scrolling down, and looking at the refactored
code and pictures describing how the effect works.&lt;br&gt;
&lt;br&gt;
Enjoy!&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;#define&lt;/span&gt; readkey &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; System; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;namespace&lt;/span&gt; m7tr1x
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;class&lt;/span&gt; Program
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; Main(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt;[
] args) { Console.Title &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"tH3
M7tr1x 3ff3&amp;lt;t"&lt;/span&gt;; Console.ForegroundColor &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; ConsoleColor.DarkGreen;
Console.WindowLeft &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Console.WindowTop &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; 0;
Console.WindowHeight &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Console.BufferHeight &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Console.LargestWindowHeight;
Console.WindowWidth &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Console.BufferWidth &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Console.LargestWindowWidth; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;#if&lt;/span&gt; readkey
Console.WriteLine(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"H1T
7NY K3Y T0 C0NT1NU3 =/"&lt;/span&gt;); Console.ReadKey(); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;#endif&lt;/span&gt; Console.CursorVisible &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;false&lt;/span&gt;; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; width,
height; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;[
] y; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;[
] l; Initialize(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; width, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; height, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; y, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; l); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; ms; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;while&lt;/span&gt; ( &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;true&lt;/span&gt; )
{ DateTime t1 &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; DateTime.Now;
MatrixStep(width, height, y, l); ms &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; 10 &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;-&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;)(
(TimeSpan)( DateTime.Now &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;-&lt;/span&gt; t1
) ).TotalMilliseconds; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (
ms &amp;gt; 0 ) System.Threading.Thread.Sleep(ms); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (
Console.KeyAvailable ) &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (
Console.ReadKey().Key == ConsoleKey.F5 ) Initialize(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; width, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; height, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; y, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; l);
} } &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;bool&lt;/span&gt; thistime &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;false&lt;/span&gt;; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;private&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; MatrixStep(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; width, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; height, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;[
] y, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;[
] l) { &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; x;
thistime &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; !thistime; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;for&lt;/span&gt; (
x &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; 0
; x &amp;lt; width ; ++x ) { &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (
x &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;%&lt;/span&gt; 11
== 10 ) { &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (
!thistime ) &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;continue&lt;/span&gt;;
Console.ForegroundColor &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; ConsoleColor.White;
} &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;else&lt;/span&gt; {
Console.ForegroundColor &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; ConsoleColor.DarkGreen;
Console.SetCursorPosition(x, inBoxY(y[x] &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;-&lt;/span&gt; 2 &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;-&lt;/span&gt; (
l[x] &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;/&lt;/span&gt; 40 &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;*&lt;/span&gt; 2
), height)); Console.Write(R); Console.ForegroundColor &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; ConsoleColor.Green;
} Console.SetCursorPosition(x, y[x]); Console.Write(R); y[x] &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; inBoxY(y[x] &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; 1,
height); Console.SetCursorPosition(x, inBoxY(y[x] &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;-&lt;/span&gt; l[x],
height)); Console.Write(' '); } } &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;private&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; Initialize(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; width, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; height, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;[
] y, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;[
] l) { &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; h1; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; h2 &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; (
h1 &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; (
height &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Console.WindowHeight
) &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;/&lt;/span&gt; 2
) &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;/&lt;/span&gt; 2;
width &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Console.WindowWidth &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;-&lt;/span&gt; 1;
y &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;[width];
l &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;[width]; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; x;
Console.Clear(); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;for&lt;/span&gt; (
x &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; 0
; x &amp;lt; width ; ++x ) { y[x] &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; r.Next(height);
l[x] &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; r.Next(h2 &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;*&lt;/span&gt; (
( x &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;%&lt;/span&gt; 11
!&lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; 10
) ? 2 : 1 ), h1 &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;*&lt;/span&gt; (
( x &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;%&lt;/span&gt; 11
!&lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; 10
) ? 2 : 1 )); } } &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; Random
r &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; Random(); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;char&lt;/span&gt; R
{ get { &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; t &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; r.Next(10); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (
t &amp;lt;= 2 ) &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;char&lt;/span&gt;)(
'0' &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; r.Next(10)
); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;else&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (
t &amp;lt;= 4 ) &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;char&lt;/span&gt;)(
'a' &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; r.Next(27)
); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;else&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (
t &amp;lt;= 6 ) &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;char&lt;/span&gt;)(
'A' &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; r.Next(27)
); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;else&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;char&lt;/span&gt;)(
r.Next(32, 255) ); } } &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; inBoxY(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; n, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; height)
{ n &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; n &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;%&lt;/span&gt; height; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (
n &amp;lt; 0 ) &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; n &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; height; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;else&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; n;
} } }&lt;/span&gt;&lt;/pre&gt;Here is the refactored code:&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; System; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;namespace&lt;/span&gt; matrix
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;class&lt;/span&gt; Program
{ &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
fields&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; Random
rand &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; Random(); &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
properties&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;char&lt;/span&gt; AsciiCharacter
{ get { &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; t &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; rand.Next(10); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (t
&amp;lt;= 2) &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
returns a number&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;char&lt;/span&gt;)('0' &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; rand.Next(10)); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;else&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (t
&amp;lt;= 4) &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
small letter&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;char&lt;/span&gt;)('a' &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; rand.Next(27)); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;else&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (t
&amp;lt;= 6) &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
capital letter&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;char&lt;/span&gt;)('A' &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; rand.Next(27)); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;else&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
any ascii character&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;char&lt;/span&gt;)(rand.Next(32,
255)); } } &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
methods&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; Main()
{ Console.ForegroundColor &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; ConsoleColor.DarkGreen;
Console.WindowLeft &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Console.WindowTop &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; 0;
Console.WindowHeight &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Console.BufferHeight &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Console.LargestWindowHeight;
Console.WindowWidth &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Console.BufferWidth &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Console.LargestWindowWidth;
Console.WriteLine(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Hit
Any Key To Continue"&lt;/span&gt;); Console.ReadKey(); Console.CursorVisible &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;false&lt;/span&gt;; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; width,
height; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
setup array of starting y values&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;[]
y; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
width was 209, height was 81&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
setup the screen and initial conditions of y&lt;/span&gt; Initialize(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; width, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; height, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; y); &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
do the Matrix effect&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
every loop all y's get incremented by 1&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;while&lt;/span&gt; ( &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;true&lt;/span&gt; )
UpdateAllColumns(width, height, y); } &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;private&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; UpdateAllColumns(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; width, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; height, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;[]
y) { &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; x; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
draws 3 characters in each x column each time... &lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
a dark green, light green, and a space&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
y is the position on the screen&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
y[x] increments 1 each time so each loop does the same thing but down 1 y value&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;for&lt;/span&gt; (
x &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; 0
; x &amp;lt; width ; ++x ) { &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
the bright green character&lt;/span&gt; Console.ForegroundColor &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; ConsoleColor.Green;
Console.SetCursorPosition(x, y[x]); Console.Write(AsciiCharacter); &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
the dark green character - 2 positions above the bright green character&lt;/span&gt; Console.ForegroundColor &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; ConsoleColor.DarkGreen; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; temp &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; y[x] &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;-&lt;/span&gt; 2;
Console.SetCursorPosition(x, inScreenYPosition(temp, height)); Console.Write(AsciiCharacter); &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
the 'space' - 20 positions above the bright green character&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; temp1 &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; y[x] &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;-&lt;/span&gt; 20;
Console.SetCursorPosition(x, inScreenYPosition(temp1, height)); Console.Write(' '); &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
increment y&lt;/span&gt; y[x] &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; inScreenYPosition(y[x] &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; 1,
height); } &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
F5 to reset, F11 to pause and unpause&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (Console.KeyAvailable)
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (Console.ReadKey().Key
== ConsoleKey.F5) Initialize(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; width, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; height, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; y); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (Console.ReadKey().Key
== ConsoleKey.F11) System.Threading.Thread.Sleep(1); } } &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
Deals with what happens when y position is off screen&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; inScreenYPosition(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; yPosition, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; height)
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (yPosition
&amp;lt; 0) &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; yPosition &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; height; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;else&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (yPosition
&amp;lt; height) &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; yPosition; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;else&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; 0;
} &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
only called once at the start&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;private&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; Initialize(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; width, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; height, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;[]
y) { height &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Console.WindowHeight;
width &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Console.WindowWidth &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;-&lt;/span&gt; 1; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
209 for me.. starting y positions of bright green characters&lt;/span&gt; y &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;[width];
Console.Clear(); &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
loops 209 times for me&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;for&lt;/span&gt; ( &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; x &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; 0
; x &amp;lt; width ; ++x ) { &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
gets random number between 0 and 81&lt;/span&gt; y[x] &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; rand.Next(height);
} } } }&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
how it works:&lt;br&gt;
&lt;br&gt;
The screen draws each column.. my screen is 208 wide.. so it loops 208 times, each
time drawing a bright green character, dark green character, and a space.&lt;br&gt;
&lt;br&gt;
&lt;img src="http://www.programgood.net/content/binary/number1.jpg" border="0"&gt;
&lt;br&gt;
&lt;br&gt;
The second loop.. the y value has been incremented by 1.&lt;br&gt;
&lt;br&gt;
&lt;img src="http://www.programgood.net/content/binary/number2.jpg" border="0"&gt;
&lt;br&gt;
&lt;br&gt;
The 3rd loop&lt;br&gt;
&lt;br&gt;
&lt;img src="http://www.programgood.net/content/binary/number3.jpg" border="0"&gt;
&lt;br&gt;
&lt;br&gt;
Enjoy!&lt;br&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=fd2843fb-2372-4c78-bf60-4269cf0468cd" /&gt;</description>
      <comments>http://www.programgood.net/CommentView,guid,fd2843fb-2372-4c78-bf60-4269cf0468cd.aspx</comments>
      <category>Events</category>
      <category>Object Oriented Programming</category>
    </item>
  </channel>
</rss>