Categories
Internet Application Development

FIT5032: Week 6

Internet Application Development week 6, an introduction to C#.

The fist part of the lecture covered the basic data types and operators (most of which are the same as Java). Control structures and operators came next, again these reflected Java very closely.

Internet Application Development week 6, an introduction to C#.

The fist part of the lecture covered the basic data types and operators (most of which are the same as Java). Control structures and operators came next, again these reflected Java very closely.

Collections in the C-Sharp language are again a mirror of the Java language.

Functions are the methods of Java:

1
2
3
4
5
6
7
string MyFirstFunction(string Name, int Age)
{
...
...
...
return "Confirmed";
}
its ok for microsoft to copy open source but not the other way around...

To give a feel for the syntax and a useful tool, the code snippet below draws a table of web server information dynamically.

1
2
3
4
<!--Page Language="c#"-->
<script type="text/javascript">// <![CDATA[
     void Page_Load()     {       Table tblVariables = new Table();       tblVariables.GridLines = GridLines.Both;       TableRow tr;       TableCell tcName;       TableCell tcValue;       foreach (string strName in Request.ServerVariables)       {         tr = new TableRow();         tr.VerticalAlign = VerticalAlign.Top;         tcName = new TableCell();         tcName.Font.Bold = true;         tcName.Text = strName;         tcValue = new TableCell();         tcValue.Text = Request.ServerVariables[strName]+" ";         tr.Cells.Add(tcName);         tr.Cells.Add(tcValue);         tblVariables.Rows.Add(tr);       }          Page.Controls.Add(tblVariables);     } // >
// ]]></script>

I feel a little uneasy with the object oriented nature of C# and how functions associated with specific pages can be associated with the object paradigm. As with any coding language the best way is to start writing it!

Another quick example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!--Page Language="c#"-->
<script type="text/javascript">// <![CDATA[
  void Increment (ref int Number)
  {
    Number++;
    Display1.Text = "The variable Number is "
      + Number.ToString();
  }</div>
<div  mce_tmp="1">  void Page_Load()
  {
    int theNumber = 1;
    Increment(ref theNumber);
    Display2.Text = "The variable theNumber is "
      + theNumber.ToString();
}
// ]]></script>

[/code]
<!--Page Language="c#"-->
<script type="text/javascript">// <![CDATA[
     void Page_Load()     {       Table tblVariables = new Table();       tblVariables.GridLines = GridLines.Both;       TableRow tr;       TableCell tcName;       TableCell tcValue;       foreach (string strName in Request.ServerVariables)       {         tr = new TableRow();         tr.VerticalAlign = VerticalAlign.Top;         tcName = new TableCell();         tcName.Font.Bold = true;         tcName.Text = strName;         tcValue = new TableCell();         tcValue.Text = Request.ServerVariables[strName]+" ";         tr.Cells.Add(tcName);         tr.Cells.Add(tcValue);         tblVariables.Rows.Add(tr);       }          Page.Controls.Add(tblVariables);     } // >
// ]]></script>

[/code]

I feel a little uneasy with the object oriented nature of C# and how functions associated with specific pages can be associated with the object paradigm. As with any coding language the best way is to start writing it!

Another quick example:
[code]
<!--Page Language="c#"-->
<script type="text/javascript">// <![CDATA[
  void Increment (ref int Number)
  {
    Number++;
    Display1.Text = "The variable Number is "
      + Number.ToString();
  }</div>
<div  mce_tmp="1">  void Page_Load()
  {
    int theNumber = 1;
    Increment(ref theNumber);
    Display2.Text = "The variable theNumber is "
      + theNumber.ToString();
}
// ]]></script>

Leave a Reply

Your email address will not be published. Required fields are marked *