Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Dave http://pedotnet.blogspot.com

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Syntax-at-a-Glance for the C# programming language

// Copyright (C) 2001 StructureByDesign. All Rights Reserved.

   1  
   2  // CLASS1.CS -- Syntax-at-a-Glance for the C# programming language.
   3  // A quick code reference for programmers who work in many languages.
   4  // Executable code, minimal comments document the essence of the language.
   5  
   6  
   7  using System;
   8  using System.Collections;
   9  using System.IO;
  10  
  11  namespace StructureByDesign.Syntax
  12  {
  13  public class Class1: Object
  14  {
  15      public static int Main(string[] args)       // Entry point.
  16      {
  17          System.Console.WriteLine("Hello");
  18          Class2 aclass2 = new Class2();
  19          aclass2.run();
  20          return 0;
  21      }
  22  }
  23  
  24  interface Interface1
  25  {
  26      void run();
  27  }
  28  
  29  class Class2: Class1, Interface1
  30  {
  31      public const int CONSTANT = 1;          // Access not restricted, implicitly static.
  32      private int m_intPrivateField;          // Access limited to containing type.
  33      public Class2() : base()                // Constructor.
  34      {
  35          initialize();
  36      }
  37      protected void initialize()             // Object initialization.
  38      {                                       // Access limited to containing class or types derived.
  39          Number = 1;
  40      }
  41      protected int Number                    // Language property feature.
  42      {
  43          get
  44          {
  45              return m_intPrivateField;
  46          }
  47          set
  48          {
  49              m_intPrivateField = value;      // Implicit parameter.
  50          }
  51      }
  52      public void run()
  53      {
  54          anonymousCode();
  55          arrays();
  56          collections();
  57          comparison();
  58          control();
  59          filesStreamsAndExceptions();
  60          numbersAndMath();
  61          primitivesAndConstants();
  62          runtimeTyping();
  63          strings();
  64      }
  65      void anonymousCode()
  66      {
  67          Delegate adelegate = new Delegate(Run);
  68          adelegate();
  69      }
  70      delegate void Delegate();
  71      void Run()
  72      {
  73          Console.WriteLine("Run");
  74      }
  75      void arrays()
  76      {
  77          int[] arrayOfInts = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  78          arrayOfInts[0] = 9;
  79          assert(arrayOfInts[0] == arrayOfInts[9]);
  80  
  81          String[] arrayOfStrings = new String[10];
  82          assert(arrayOfStrings[0] == null);
  83          assert(arrayOfStrings.Length == 10);
  84  
  85          arrayOfStrings = new String[] { "one", "two" };
  86  
  87          byte[,] arrayOfBytes = { {0,0,0},
  88                                   {0,1,2},
  89                                   {0,2,4}};
  90          assert(arrayOfBytes[2,2] == 4);
  91      }
  92      void collections()
  93      {
  94          IList ailist = new ArrayList();
  95          ailist.Add("zero"); ailist.Add("one"); ailist.Add("three");
  96          ailist[2] = "two";
  97          assert(ailist[2].Equals("two"));
  98          ailist.Remove("two");
  99          ((ArrayList)ailist).Sort();
 100          for(IEnumerator aie = ((ArrayList)ailist).GetEnumerator(); aie.MoveNext(); )
 101              ;
 102          foreach(String astring in ailist)
 103              ;
 104  
 105          IDictionary aidictionary = new Hashtable();
 106          aidictionary.Add("key", "value");
 107          assert(aidictionary["key"].Equals("value"));
 108  
 109          // Set not available.
 110      }
 111      void comparison()
 112      {
 113          int aint1 = 1;
 114          int aint2 = 2;
 115          int aint = 1;
 116          String astring1 = "one";
 117          String astring2 = "two";
 118          String astring = astring1;
 119  
 120          assert(aint == aint1);
 121          assert(aint1 != aint2);
 122          assert(astring == astring1);
 123          assert(astring1 == String.Copy("one"));         // For strings == is overloaded to compare values.
 124          assert(!astring1.Equals(astring2));
 125          assert(astring1.Equals(String.Copy("one")));
 126  
 127          astring = null;
 128          if (astring != null && astring.Length > 0)      // Conditional evaluation.
 129              assert(false);
 130  
 131          if (aint2 < 0 || 1 < aint2)
 132              assert(true);
 133      }
 134      void control()
 135      {
 136          if (true)
 137              assert(true);
 138          else
 139              assert(false);
 140          /////
 141          switch ('b') {
 142              case 'a':
 143                  assert(false);
 144                  break;
 145              case 'b':
 146                  assert(true);
 147                  break;
 148              default:
 149                  assert(false);
 150                  break;
 151          }
 152          /////
 153          for (int ai1 = 0; ai1 < 10; ai1++)
 154              assert(true);
 155          /////
 156          int ai = 0;
 157          while (ai < 10) {
 158              assert(true);
 159              ai++;
 160          }
 161  
 162          do
 163              ai--;
 164          while (ai > 0);
 165  
 166          for (int x = 0; x < 10; x++)        // Labeled break/continue not available.
 167              for (int y = 0; y < 10; y++)
 168                  if (x == 9)
 169                      break;
 170                  else
 171                      continue;
 172      }
 173      void filesStreamsAndExceptions()
 174      {
 175          FileInfo afileinfo = new FileInfo("list.txt");
 176          try {
 177              StreamWriter asw = new StreamWriter("list.txt");
 178              asw.WriteLine("line");
 179              asw.WriteLine("line");
 180              asw.Close();
 181  
 182              assert(afileinfo.Exists);
 183  
 184              StreamReader asr = new StreamReader("list.txt");
 185              String astringLine;
 186              while ((astringLine = asr.ReadLine()) != null)
 187                  assert(astringLine.Equals("line"));
 188              asr.Close();
 189          } catch (IOException aexception) {
 190              System.Console.WriteLine(aexception.Message);
 191              throw new NotSupportedException();
 192          }
 193          finally {
 194              afileinfo.Delete();
 195          }
 196      }
 197      void numbersAndMath()
 198      {
 199          assert(Int32.Parse("123") == 123);
 200          assert(123.ToString().Equals("123"));
 201  
 202          assert(Math.PI.ToString("n3").Equals("3.142"));
 203  
 204          assert(Int32.MaxValue < Int64.MaxValue);
 205  
 206          assert(Math.Abs(Math.Sin(0) - 0) <= Double.Epsilon);
 207          assert(Math.Abs(Math.Cos(0) - 1) <= Double.Epsilon);
 208          assert(Math.Abs(Math.Tan(0) - 0) <= Double.Epsilon);
 209  
 210          assert(Math.Abs(Math.Sqrt(4) - 2) <= Double.Epsilon);
 211          assert(Math.Abs(Math.Pow(3,3) - 27) <= Double.Epsilon);
 212  
 213          assert(Math.Max(0,1) == 1);
 214          assert(Math.Min(0,1) == 0);
 215  
 216          assert(Math.Abs(Math.Ceiling(9.87) - 10.0) <= Double.Epsilon);
 217          assert(Math.Abs(Math.Floor(9.87) - 9.0) <= Double.Epsilon);
 218          assert(Math.Round(9.87) == 10);
 219  
 220          Random arandom = new Random();
 221          double adouble = arandom.NextDouble();
 222          assert(0.0 <= adouble && adouble < 1.0);
 223          int aint = arandom.Next(10);
 224          assert(0 <= aint && aint < 10);
 225      }
 226      enum Season: byte { Spring=0, Summer, Fall, Winter };
 227  
 228      void primitivesAndConstants()
 229      {
 230          bool abool = false;
 231          char achar = 'A';           // 16 bits, Unicode
 232  
 233          byte abyte = 0x0;           // 8 bits, unsigned, hex constant
 234          sbyte asbyte = 0;           // 8 bits, signed
 235  
 236          short ashort = 0;           // 16 bits, signed
 237          ushort aushort = 0;         // 16 bits, unsigned
 238  
 239          int aint = 0;               // 32 bits, signed
 240          uint aunit = 0;             // 32 bits, unsigned
 241  
 242          long along = 0L;            // 64 bits, signed
 243          ulong aulong = 0;           // 64 bits, unsigned
 244  
 245          float afloat = 0.0F;        // 32 bits
 246          double adouble = 0.0;       // 64 bits
 247  
 248          decimal adecimal = 0;       // 128 bits, financial calculations
 249  
 250          Season aseason = Season.Fall;
 251          assert((byte)aseason == 2);
 252      }
 253      void runtimeTyping()
 254      {
 255          assert(new int[] { 1 } is int[]);
 256          assert(new ArrayList() is ArrayList);
 257  
 258          assert((new ArrayList()).GetType() == typeof(ArrayList));
 259          assert(typeof(Int32) is Type);      // Type of primitive type.
 260  
 261          assert(Type.GetType("System.Collections.ArrayList") == typeof(ArrayList));
 262      }
 263      void strings()
 264      {
 265          String astring1 = "one";
 266          String astring2 = "TWO";
 267  
 268          assert((astring1 + "/" + astring2).Equals("one/TWO"));
 269          assert(astring2.ToLower().Equals("two"));   // Equals ignoring case not available.
 270          assert(astring1.Length == 3);
 271          assert(astring1.Substring(0,2).Equals("on"));
 272          assert(astring1[2] == 'e');
 273          assert(astring1.ToUpper().Equals("ONE"));
 274          assert(astring2.ToLower().Equals("two"));
 275          assert(astring1.CompareTo("p") < 0);
 276          assert(astring1.IndexOf('e') == 2);
 277          assert(astring1.IndexOf("ne") == 1);
 278          assert(astring1.Trim().Length == astring1.Length);
 279  
 280          assert(Char.IsDigit('1'));
 281          assert(Char.IsLetter('a'));
 282          assert(Char.IsWhiteSpace('\t'));
 283          assert(Char.ToLower('A') == 'a');
 284          assert(Char.ToUpper('a') == 'A');
 285      }
 286      private void assert(bool abool)
 287      {
 288          if (!abool)
 289              throw new Exception("assert failed");
 290      }
 291  }
 292  }

DELETE - SQL

// description of your code here

   1  
   2  DELETE ... 
   3      [ FROM ... ] 
   4      [ ... JOIN ... ] 
   5      [ WHERE ... ] 
   6  
   7  // FULL Syntax follows:
   8  DELETE [ FROM ] 
   9      {
  10         [ database. ] [ owner. ] table_name 
  11           [
  12             WITH (  INDEX ( Index_1,   [ index_2,  ...,  n ] ) 
  13                        | FASTFIRSTROW 
  14                        | HOLDLOCK 
  15                        | PAGLOCK 
  16                        | READCOMMITTED 
  17                        | REPEATABLEREAD 
  18                        | ROWLOCK 
  19                        | SERIALIZABLE 
  20                        | TABLOCK 
  21                        | TABLOCKX 
  22                        [   ...   n  |  ...,  n ] 
  23                       )
  24         ]
  25       |
  26         OPENQUERY( server, 'query' ) 
  27       |
  28         OPENROWSET( 'provider_name', 
  29                                   { 'datasource';'user_id';'password',  |  'provider_string', }
  30                                   { [ catalog. ] [ schema. ] object  |  'query' }
  31                                 ) 
  32       |
  33         view_name 
  34      }
  35  
  36      [
  37        FROM 
  38        {
  39            derived_table 
  40              [ [ AS ] table_alias ]
  41              [ ( column_alias_1,   [ column_alias_2,   ...,  n ]  )  ]
  42          |
  43            CONTAINSTABLE ( table, column  |  *, 'search_conditions' ) 
  44              [ [ AS ] table_alias ]
  45          |
  46            FREETEXTTABLE ( table, column  |  *, 'free_text_string' ) 
  47              [ [ AS ] table_alias ]
  48          |
  49            table_name [ [ AS ] table_alias ]
  50              [
  51                 WITH (  INDEX ( Index_1,   [ index_2,   ...,  n ]  ) 
  52                            | FASTFIRSTROW 
  53                            | HOLDLOCK 
  54                            | NOLOCK 
  55                            | PAGLOCK 
  56                            | READCOMMITTED 
  57                            | READPAST 
  58                            | READUNCOMMITTED 
  59                            | REPEATABLEREAD 
  60                            | ROWLOCK 
  61                            | SERIALIZABLE 
  62                            | TABLOCK 
  63                            | TABLOCKX 
  64                            | UPDLOCK 
  65                            [ ...   n  |  ...,  n ] 
  66                           )
  67              ]
  68          |
  69            view_name [ [ AS ] table_alias ]
  70        }
  71  
  72  
  73  
  74  
  75  
  76        [
  77            INNER JOIN  |  LEFT [ OUTER ] JOIN  |  RIGHT [ OUTER ] JOIN 
  78              {
  79                 derived_table [ ON search_conditions ]
  80               |
  81                 OPENQUERY( server, 'query' ) [ ON search_conditions ]
  82               |
  83                 OPENROWSET
  84                                 ( 'provider_name', 
  85                                   { 'datasource';'user_id';'password',  |  'provider_string', }
  86                                   { [ catalog. ] [ schema. ] object  |  'query' }
  87                                 ) [ ON search_conditions ]
  88               | 
  89                 table_name [ ON search_conditions ]
  90               | 
  91                 view_name [ ON search_conditions ]
  92              }
  93              [   ...,  n ]
  94            |
  95            CROSS JOIN  |  FULL [ OUTER ] JOIN 
  96              {
  97                 derived_table 
  98               | 
  99                 OPENQUERY( server, 'query' ) 
 100               |
 101                 OPENROWSET
 102                                 ( 'provider_name', 
 103                                   { 'datasource';'user_id';'password',  |  'provider_string', }
 104                                   { [ catalog. ] [ schema. ] object  |  'query' }
 105                                 ) 
 106               | 
 107                 table_name 
 108               | 
 109                 view_name 
 110              }
 111              [   ...,  n ]
 112         ]
 113     ] 
 114  
 115     [
 116        {
 117           WHERE search_conditions 
 118         |
 119           WHERE CURRENT OF [ GLOBAL ] cursor_name 
 120         |
 121           WHERE CURRENT OF cursor_variable_name 
 122        }
 123           [
 124             OPTION (  FAST number_rows 
 125                            | FORCE ORDER 
 126                            | HASH GROUP 
 127                            | ORDER GROUP 
 128                            | HASH JOIN 
 129                            | LOOP JOIN 
 130                            | MERGE JOIN 
 131                            | KEEP PLAN 
 132                            | MAXDOP 
 133                            | ROBUST PLAN 
 134                            | CONCAT UNION 
 135                            | HASH UNION 
 136                            | MERGE UNION 
 137                            [   ...,  n ]
 138                          )
 139           ]
 140     ]

//Full explanation follows:

KEYWORDS Keywords are denoted with upper case letters. Obey the spelling.

variables All user-supplied variables are denoted with lower case letters.

..., n Signifies that there can be more than one value in a comma delimited list. Note that the dots and n are not part of the code and must not appear in the SQL query.

... n Signifies that there can be more than one value in a blank space delimited list. Note that the dots and n are not part of the code and must not appear in the SQL query.

{ } Signifies that all, or some portion, of the code elements between the braces are required elements and must appear in the SQL query. Note that these braces are not part of the code and must not appear in the SQL query.

[ ] Signifies that the code elements between the square brackets can optionally appear in the SQL query, but are not required. Note that these brackets are not part of the code and must not appear in the SQL query.

| The or symbol signifies that you may use only one of the code elements or values from the possible choices. Note that the or symbol is not part of the code and must not appear in the SQL query.
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS