home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / aspplus / doc / langsupport.aspx < prev    next >
Encoding:
Text File  |  2000-06-11  |  9.7 KB  |  567 lines

  1.  
  2. <!-- #include virtual="/quickstart/aspplus/include/header.inc" -->
  3.  
  4. <h4>Language Support</h4>
  5.  
  6. ASP+ currently offers built-in support for three languages, <b>C#</b> (pronounced "C Sharp"), <b>Visual Basic</b>, and 
  7. <b>JScript</b>.  
  8.  
  9. <p>The exercises and code samples in this tutorial demonstrate the use of the VB and C# languages for building ASP+
  10. web applications.  For information regarding the syntax of the other languages, refer to the complete documentation for the
  11. NGWS SDK.
  12.  
  13. You may use the following table to understand the code samples in this tutorial and the differences between the two languages:
  14.  
  15. <div style="margin:15,15,15,15">
  16.  
  17. <p>
  18.  
  19. <table class="table2" cellpadding=5 cellspacing=0 border=1>
  20. <tr><th>C# Syntax</th><th>VB Syntax</th></tr>
  21.  
  22. <tr>
  23.   <td colspan="2"><b>Variable Declarations</td>
  24. </tr>
  25. <tr>
  26.   <td style="background-color:white">
  27. <div class="code"><xmp>
  28. int x;
  29. String s;
  30. String s1, s2;
  31. Object o;
  32. Object obj = new Object();
  33. public String name;
  34. </xmp></div>
  35.   </td>
  36.   <td style="background-color:white">
  37. <div class="code"><xmp>
  38. Dim x As Integer
  39. Dim s As String
  40. Dim s1, s2 As String
  41. Dim o 'Implicitly Object
  42. Dim obj As New Object()
  43. Public name As String
  44. </xmp></div>
  45.   </td>
  46. </tr>
  47.  
  48.  
  49. <tr>
  50.   <td colspan="2"><b>Statements</td>
  51. </tr>
  52. <tr>
  53.   <td style="background-color:white">
  54. <div class="code"><xmp>
  55. Response.Write("foo");
  56. </xmp></div>
  57.   </td>
  58.   <td style="background-color:white">
  59. <div class="code"><xmp>
  60. Response.Write("foo")
  61. </xmp></div>
  62.   </td>
  63. </tr>
  64.  
  65. <tr>
  66.   <td colspan="2"><b>Comments</td>
  67. </tr>
  68. <tr>
  69.   <td style="background-color:white">
  70. <div class="code"><xmp>
  71. // This is a comment
  72.  
  73. /*
  74. This 
  75. is
  76. a
  77. multi-line
  78. comment
  79. */
  80. </xmp></div>
  81.   </td>
  82.   <td style="background-color:white">
  83. <div class="code"><xmp>
  84. ' This is a comment
  85.  
  86. ' This 
  87. ' is
  88. ' a
  89. ' multi-line
  90. ' comment
  91. </xmp></div>
  92.   </td>
  93. </tr>
  94.  
  95. <tr>
  96.   <td colspan="2"><b>Accessing Indexed Properties</td>
  97. </tr>
  98. <tr>
  99.   <td style="background-color:white">
  100. <div class="code"><xmp>
  101. String s = Request.QueryString["Name"];
  102. String value = Request.Cookies["key"];
  103. </xmp></div>
  104.   </td>
  105.   <td style="background-color:white">
  106. <div class="code"><xmp>
  107. Dim s, value As String
  108. s = Request.QueryString("Name")
  109. value = Request.Cookies("Key").Value  
  110.  
  111. 'Note that default non-indexed properties 
  112. 'must be explicitly named in VB
  113. </xmp></div>
  114.   </td>
  115. </tr>
  116.  
  117. <tr>
  118.   <td colspan="2"><b>Declaring Simple Properties</td>
  119. </tr>
  120. <tr>
  121.   <td style="background-color:white">
  122. <div class="code"><xmp>
  123. public String name {
  124.  
  125.   get { 
  126.     ... 
  127.     return ...;
  128.   }
  129.  
  130.   set {
  131.     ... = value;
  132.   }
  133.  
  134. }
  135. </xmp></div>
  136.   </td>
  137.   <td style="background-color:white">
  138. <div class="code"><xmp>
  139. Public Property Name As String
  140.  
  141.   Get 
  142.     ... 
  143.     Return ...;
  144.   End Get
  145.  
  146.   Set
  147.     ... = Value;
  148.   End Set
  149.  
  150. End Property
  151. </xmp></div>
  152.   </td>
  153. </tr>
  154.  
  155.  
  156. <tr>
  157.   <td colspan="2"><b>Arrays</td>
  158. </tr>
  159. <tr>
  160.   <td style="background-color:white">
  161. <div class="code"><xmp>
  162.     String[] a = new String[3];
  163.     a[0] = "1";
  164.     a[1] = "2";
  165.     a[2] = "3";
  166.  
  167.     String[][] a = new String[3][3];
  168.     a[0][0] = "1";
  169.     a[1][0] = "2";
  170.     a[2][0] = "3";
  171. </xmp></div>
  172.   </td>
  173.   <td style="background-color:white">
  174. <div class="code"><xmp>
  175.   Dim a(3) As String
  176.   a(0) = "1"
  177.   a(1) = "2"
  178.   a(2) = "3"
  179.  
  180.   Dim a(3,3) As String
  181.   a(0,0) = "1"
  182.   a(1,0) = "2"
  183.   a(2,0) = "3"
  184.  
  185.   ' Array of unspecified bounds (NA in C#)
  186.  
  187.   Dim a() As String
  188.   a(0,0) = "1"
  189.   a(1,0) = "2"
  190.   a(2,0) = "3"
  191.  
  192.   Dim a(,) As String
  193.   a(0,0) = "1"
  194.   a(1,0) = "2"
  195.   a(2,0) = "3"
  196. </xmp></div>
  197.   </td>
  198. </tr>
  199.  
  200. <tr>
  201.   <td colspan="2"><b>Initialization</td>
  202. </tr>
  203. <tr>
  204.   <td style="background-color:white">
  205. <div class="code"><xmp>
  206. String s = "Hello World";
  207. int i = 1
  208. double[] a =  { 3.00, 4.00, 5.00 };
  209. </xmp></div>
  210.   </td>
  211.   <td style="background-color:white">
  212. <div class="code"><xmp>
  213. Dim s As String = "Hello World"
  214. Dim i As Integer = 1
  215. Dim a() As Double = { 3.00, 4.00, 5.00 }
  216. </xmp></div>
  217.   </td>
  218. </tr>
  219.  
  220.  
  221. <tr>
  222.   <td colspan="2"><b>If Statements</td>
  223. </tr>
  224. <tr>
  225.   <td style="background-color:white">
  226. <div class="code"><xmp>
  227. if (Request.QueryString != null) {
  228.   ...
  229. }
  230. </xmp></div>
  231.   </td>
  232.   <td style="background-color:white">
  233. <div class="code"><xmp>
  234. If Not (Request.QueryString = Null)
  235.   ...
  236. End If
  237. </xmp></div>
  238.   </td>
  239. </tr>
  240.  
  241.  
  242. <tr>
  243.   <td colspan="2"><b>Case Statements</td>
  244. </tr>
  245. <tr>
  246.   <td style="background-color:white">
  247. <div class="code"><xmp>
  248. switch (FirstName) {
  249.   case "John" :
  250.     ...
  251.     break;
  252.   case "Paul" :
  253.     ...
  254.     break;
  255.   case "Ringo" :
  256.     ...
  257.     break;
  258. }
  259. </xmp></div>
  260.   </td>
  261.   <td style="background-color:white">
  262. <div class="code"><xmp>
  263. Select (FirstName)
  264.   case "John" :
  265.     ...
  266.   case "Paul" :
  267.     ...
  268.   case "Ringo" :
  269.     ...
  270. End Select
  271. </xmp></div>
  272.   </td>
  273. </tr>
  274.  
  275.  
  276. <tr>
  277.   <td colspan="2"><b>For Loops</td>
  278. </tr>
  279. <tr>
  280.   <td style="background-color:white">
  281. <div class="code"><xmp>
  282. for (int i=0; i<3; i++)
  283.   a(i) = "test";
  284. </xmp></div>
  285.   </td>
  286.   <td style="background-color:white">
  287. <div class="code"><xmp>
  288.   Dim I As Integer
  289.   For I = 0 To 2 
  290.     a(I) = "test"
  291.   Next
  292. </xmp></div>
  293.   </td>
  294. </tr>
  295.  
  296. <tr>
  297.   <td colspan="2"><b>While Loops</td>
  298. </tr>
  299. <tr>
  300.   <td style="background-color:white">
  301. <div class="code"><xmp>
  302. int i = 0;
  303. while (i<3) {
  304.   Console.WriteLine(i.ToString());
  305.   i += 1;
  306. }
  307. </xmp></div>
  308.   </td>
  309.   <td style="background-color:white">
  310. <div class="code"><xmp>
  311. Dim I As Integer
  312. I = 0
  313. Do While I < 3
  314.   Console.WriteLine(I.ToString())
  315.   I = I + 1
  316. Loop
  317. </xmp></div>
  318.   </td>
  319. </tr>
  320.  
  321.  
  322.  
  323.  
  324. <tr>
  325.   <td colspan="2"><b>String Concatenation</td>
  326. </tr>
  327. <tr>
  328.   <td style="background-color:white">
  329. <div class="code"><xmp>
  330. String s1;
  331. String s2 = "hello";
  332. s2 += " world";
  333. s1 = s2 + " !!!";
  334. </xmp></div>
  335.   </td>
  336.   <td style="background-color:white">
  337. <div class="code"><xmp>
  338. Dim s1, s2 As String
  339. s2 = "hello"
  340. s2 &= " world"
  341. s1 = s2 & " !!!"
  342. </xmp></div>
  343.   </td>
  344. </tr>
  345.  
  346.  
  347. <tr>
  348.   <td colspan="2"><b>Event Handlers</td>
  349. </tr>
  350. <tr>
  351.   <td style="background-color:white">
  352. <div class="code"><xmp>
  353. void MyButton_Click(Object sender, 
  354.                             EventArgs E) {
  355. ...
  356. }
  357. </xmp></div>
  358.   </td>
  359.   <td style="background-color:white">
  360. <div class="code"><xmp>
  361. Sub MyButton_Click(Sender As Object, 
  362.                             E As EventArgs)
  363. ...
  364. End Sub
  365.  
  366. 'Note that ByVal is now the default 
  367. 'for params in VB
  368. </xmp></div>
  369.   </td>
  370. </tr>
  371.  
  372. <tr>
  373.   <td colspan="2"><b>Casting</td>
  374. </tr>
  375. <tr>
  376.   <td style="background-color:white">
  377. <div class="code"><xmp>
  378. MyObject obj = (MyObject)Session["Some Value"];
  379. IMyObject iObj = obj
  380. </xmp></div>
  381.   </td>
  382.   <td style="background-color:white">
  383. <div class="code"><xmp>
  384. Dim bj As MyObject
  385. Dim iObj As IMyObject
  386. obj = Session("Some Value")
  387. iObj = CType(obj, IMyObject)
  388. </xmp></div>
  389.   </td>
  390. </tr>
  391.  
  392. <tr>
  393.   <td colspan="2"><b>Conversion</td>
  394. </tr>
  395. <tr>
  396.   <td style="background-color:white">
  397. <div class="code"><xmp>
  398. int i = 3;
  399. String s = i.ToString();
  400. double d = Double.Parse(s);
  401. </xmp></div>
  402.   </td>
  403.   <td style="background-color:white">
  404. <div class="code"><xmp>
  405. Dim i As Integer
  406. Dim s As String
  407. Dim d As Double
  408.  
  409. i = 3
  410. s = i.ToString()
  411. d = CDbl(s) 
  412.  
  413. ' See also CDbl(...), CStr(...), ...
  414. </xmp></div>
  415.   </td>
  416. </tr>
  417.  
  418.  
  419. <tr>
  420.   <td colspan="2"><b>Class Definition w/ Inheritance</td>
  421. </tr>
  422. <tr>
  423.   <td style="background-color:white">
  424. <div class="code"><xmp>
  425. using System; 
  426.  
  427. namespace MySpace {
  428.  
  429.   public class Foo : Bar {
  430.  
  431.     int x;
  432.  
  433.     public Foo() { x = 4; }
  434.     public void Add(int x) { this.x += x; }   
  435.     public int GetNum() { return x; }   
  436.   }
  437.  
  438. }
  439.  
  440. // csc /out:librarycs.dll /t:library library.cs
  441. </xmp></div>
  442.   </td>
  443.   <td style="background-color:white">
  444. <div class="code"><xmp>
  445. Imports System
  446.  
  447. Namespace MySpace
  448.  
  449.   Public Class Foo : Inherits Bar
  450.  
  451.     Dim x As Integer
  452.  
  453.     Public Sub New()
  454.       MyBase.New()
  455.       x = 4
  456.     End Sub
  457.  
  458.     Public Sub Add(x As Integer)
  459.       Me.x = Me.x + x
  460.     End Sub
  461.  
  462.     Public Function GetNum() As Integer
  463.        Return x
  464.     End Function
  465.  
  466.   End Class
  467.  
  468. End Namespace
  469.  
  470. ' vbc /out:libraryvb.dll /t:library library.vb
  471. </xmp></div>
  472.   </td>
  473. </tr>
  474.  
  475.  
  476. <tr>
  477.   <td colspan="2"><b>Class Definition w/ A Main method</td>
  478. </tr>
  479. <tr>
  480.   <td style="background-color:white">
  481. <div class="code"><xmp>
  482. using System;
  483.  
  484. public class ConsoleCS {
  485.  
  486.   public ConsoleCS() {
  487.     Console.WriteLine("Object Created");
  488.   }
  489.  
  490.   public static void Main (String[] args) {
  491.     Console.WriteLine("Hello World");
  492.     ConsoleCS ccs = new ConsoleCS();
  493.   }
  494.  
  495. }
  496.  
  497. // csc /out:consolecs.exe /t:exe console.cs
  498. </xmp></div>
  499.   </td>
  500.   <td style="background-color:white">
  501. <div class="code"><xmp>
  502. Imports System
  503.  
  504. Public Class ConsoleVB
  505.  
  506.   Public Sub New()
  507.     MyBase.New()
  508.     Console.WriteLine("Object Created")
  509.   End Sub
  510.  
  511.   Public Shared Sub Main()
  512.     Console.WriteLine("Hello World")
  513.     Dim cvb As ConsoleVB
  514.     cvb = New ConsoleVB()
  515.   End Sub
  516.  
  517. End Class
  518.  
  519. ' vbc /out:consolevb.exe /t:exe console.vb
  520. </xmp></div>
  521.   </td>
  522. </tr>
  523.  
  524.  
  525.  
  526. <tr>
  527.   <td colspan="2"><b>Standard Module</td>
  528. </tr>
  529. <tr>
  530.   <td style="background-color:white">
  531. <div class="code"><xmp>
  532. using System;
  533.  
  534. public class Module {
  535.  
  536. public static void Main (String[] args) {
  537.   Console.WriteLine("Hello World");
  538. }
  539.  
  540. }
  541. // csc /out:consolecs.exe /t:exe console.cs
  542. </xmp></div>
  543.   </td>
  544.   <td style="background-color:white">
  545. <div class="code"><xmp>
  546. Imports System
  547.  
  548. Public Module ConsoleVB
  549.  
  550.   Public Sub Main()
  551.     Console.WriteLine("Hello World")
  552.   End Sub
  553.  
  554. End Module
  555.  
  556. ' vbc /out:consolevb.exe /t:exe console.vb
  557. </xmp></div>
  558.   </td>
  559. </tr>
  560.  
  561. </table>
  562.  
  563. <p>
  564.  
  565. </div>
  566.  
  567. <!-- #include virtual="/quickstart/aspplus/include/footer.inc" -->