bytea论坛

 找回密码
 注册
搜索
查看: 4279|回复: 2

C# Syntax Reference Card [复制链接]

Rank: 9Rank: 9Rank: 9

发表于 2010-1-28 18:26:15 |显示全部楼层
  1. // CLASS1.CS -- Syntax-at-a-Glance for the C# programming language.
  2. // A quick code reference for programmers who work in many languages.
  3. // Executable code, minimal comments document the essence of the language.
  4. // Copyright (C) 2001 StructureByDesign.  All Rights Reserved.


  5. using System;
  6. using System.Collections;
  7. using System.IO;

  8. namespace StructureByDesign.Syntax
  9. {
  10. public class Class1: Object
  11. {
  12.     public static int Main(string[] args)       // Entry point.
  13.     {
  14.         System.Console.WriteLine("Hello");
  15.         Class2 aclass2 = new Class2();
  16.         aclass2.run();
  17.         return 0;
  18.     }
  19. }

  20. interface Interface1
  21. {
  22.     void run();
  23. }

  24. class Class2: Class1, Interface1
  25. {
  26.     public const int CONSTANT = 1;          // Access not restricted, implicitly static.
  27.     private int m_intPrivateField;          // Access limited to containing type.
  28.     public Class2() : base()                // Constructor.
  29.     {
  30.         initialize();
  31.     }
  32.     protected void initialize()             // Object initialization.
  33.     {                                       // Access limited to containing class or types derived.
  34.         Number = 1;
  35.     }
  36.     protected int Number                    // Language property feature.
  37.     {
  38.         get
  39.         {
  40.             return m_intPrivateField;
  41.         }
  42.         set
  43.         {
  44.             m_intPrivateField = value;      // Implicit parameter.
  45.         }
  46.     }
  47.     public void run()
  48.     {
  49.         anonymousCode();
  50.         arrays();
  51.         collections();
  52.         comparison();
  53.         control();
  54.         filesStreamsAndExceptions();
  55.         numbersAndMath();
  56.         primitivesAndConstants();
  57.         runtimeTyping();
  58.         strings();
  59.     }
  60.     void anonymousCode()
  61.     {
  62.         Delegate adelegate = new Delegate(Run);
  63.         adelegate();
  64.     }
  65.     delegate void Delegate();
  66.     void Run()
  67.     {
  68.         Console.WriteLine("Run");
  69.     }
  70.     void arrays()
  71.     {
  72.         int[] arrayOfInts = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  73.         arrayOfInts[0] = 9;
  74.         assert(arrayOfInts[0] == arrayOfInts[9]);

  75.         String[] arrayOfStrings = new String[10];
  76.         assert(arrayOfStrings[0] == null);
  77.         assert(arrayOfStrings.Length == 10);

  78.         arrayOfStrings = new String[] { "one", "two" };

  79.         byte[,] arrayOfBytes = { {0,0,0},
  80.                                  {0,1,2},
  81.                                  {0,2,4}};
  82.         assert(arrayOfBytes[2,2] == 4);
  83.     }
  84.     void collections()
  85.     {
  86.         IList ailist = new ArrayList();
  87.         ailist.Add("zero"); ailist.Add("one"); ailist.Add("three");
  88.         ailist[2] = "two";
  89.         assert(ailist[2].Equals("two"));
  90.         ailist.Remove("two");
  91.         ((ArrayList)ailist).Sort();
  92.         for(IEnumerator aie = ((ArrayList)ailist).GetEnumerator(); aie.MoveNext(); )
  93.             ;
  94.         foreach(String astring in ailist)
  95.             ;

  96.         IDictionary aidictionary = new Hashtable();
  97.         aidictionary.Add("key", "value");
  98.         assert(aidictionary["key"].Equals("value"));

  99.         // Set not available.
  100.     }
  101.     void comparison()
  102.     {
  103.         int aint1 = 1;
  104.         int aint2 = 2;
  105.         int aint = 1;
  106.         String astring1 = "one";
  107.         String astring2 = "two";
  108.         String astring = astring1;

  109.         assert(aint == aint1);
  110.         assert(aint1 != aint2);
  111.         assert(astring == astring1);
  112.         assert(astring1 == String.Copy("one"));         // For strings == is overloaded to compare values.
  113.         assert(!astring1.Equals(astring2));
  114.         assert(astring1.Equals(String.Copy("one")));

  115.         astring = null;
  116.         if (astring != null && astring.Length > 0)      // Conditional evaluation.
  117.             assert(false);

  118.         if (aint2 < 0 || 1 < aint2)
  119.             assert(true);
  120.     }
  121.     void control()
  122.     {
  123.         if (true)
  124.             assert(true);
  125.         else
  126.             assert(false);
  127.         /////
  128.         switch ('b') {
  129.             case 'a':
  130.                 assert(false);
  131.                 break;
  132.             case 'b':
  133.                 assert(true);
  134.                 break;
  135.             default:
  136.                 assert(false);
  137.                 break;
  138.         }
  139.         /////
  140.         for (int ai1 = 0; ai1 < 10; ai1++)
  141.             assert(true);
  142.         /////
  143.         int ai = 0;
  144.         while (ai < 10) {
  145.             assert(true);
  146.             ai++;
  147.         }

  148.         do
  149.             ai--;
  150.         while (ai > 0);

  151.         for (int x = 0; x < 10; x++)        // Labeled break/continue not available.
  152.             for (int y = 0; y < 10; y++)
  153.                 if (x == 9)
  154.                     break;
  155.                 else
  156.                     continue;
  157.     }
  158.     void filesStreamsAndExceptions()
  159.     {
  160.         FileInfo afileinfo = new FileInfo("list.txt");
  161.         try {
  162.             StreamWriter asw = new StreamWriter("list.txt");
  163.             asw.WriteLine("line");
  164.             asw.WriteLine("line");
  165.             asw.Close();

  166.             assert(afileinfo.Exists);

  167.             StreamReader asr = new StreamReader("list.txt");
  168.             String astringLine;
  169.             while ((astringLine = asr.ReadLine()) != null)
  170.                 assert(astringLine.Equals("line"));
  171.             asr.Close();
  172.         } catch (IOException aexception) {
  173.             System.Console.WriteLine(aexception.Message);
  174.             throw new NotSupportedException();
  175.         }
  176.         finally {
  177.             afileinfo.Delete();
  178.         }
  179.     }
  180.     void numbersAndMath()
  181.     {
  182.         assert(Int32.Parse("123") == 123);
  183.         assert(123.ToString().Equals("123"));

  184.         assert(Math.PI.ToString("n3").Equals("3.142"));

  185.         assert(Int32.MaxValue < Int64.MaxValue);

  186.         assert(Math.Abs(Math.Sin(0) - 0) <= Double.Epsilon);
  187.         assert(Math.Abs(Math.Cos(0) - 1) <= Double.Epsilon);
  188.         assert(Math.Abs(Math.Tan(0) - 0) <= Double.Epsilon);

  189.         assert(Math.Abs(Math.Sqrt(4) - 2) <= Double.Epsilon);
  190.         assert(Math.Abs(Math.Pow(3,3) - 27) <= Double.Epsilon);

  191.         assert(Math.Max(0,1) == 1);
  192.         assert(Math.Min(0,1) == 0);

  193.         assert(Math.Abs(Math.Ceiling(9.87) - 10.0) <= Double.Epsilon);
  194.         assert(Math.Abs(Math.Floor(9.87) - 9.0) <= Double.Epsilon);
  195.         assert(Math.Round(9.87) == 10);

  196.         Random arandom = new Random();
  197.         double adouble = arandom.NextDouble();
  198.         assert(0.0 <= adouble && adouble < 1.0);
  199.         int aint = arandom.Next(10);
  200.         assert(0 <= aint && aint < 10);
  201.     }
  202.     enum Season: byte { Spring=0, Summer, Fall, Winter };

  203.     void primitivesAndConstants()
  204.     {
  205.         bool abool = false;
  206.         char achar = 'A';           // 16 bits, Unicode

  207.         byte abyte = 0x0;           // 8 bits, unsigned, hex constant
  208.         sbyte asbyte = 0;           // 8 bits, signed

  209.         short ashort = 0;           // 16 bits, signed
  210.         ushort aushort = 0;         // 16 bits, unsigned

  211.         int aint = 0;               // 32 bits, signed
  212.         uint aunit = 0;             // 32 bits, unsigned

  213.         long along = 0L;            // 64 bits, signed
  214.         ulong aulong = 0;           // 64 bits, unsigned

  215.         float afloat = 0.0F;        // 32 bits
  216.         double adouble = 0.0;       // 64 bits

  217.         decimal adecimal = 0;       // 128 bits, financial calculations

  218.         Season aseason = Season.Fall;
  219.         assert((byte)aseason == 2);
  220.     }
  221.     void runtimeTyping()
  222.     {
  223.         assert(new int[] { 1 } is int[]);
  224.         assert(new ArrayList() is ArrayList);

  225.         assert((new ArrayList()).GetType() == typeof(ArrayList));
  226.         assert(typeof(Int32) is Type);      // Type of primitive type.

  227.         assert(Type.GetType("System.Collections.ArrayList") == typeof(ArrayList));
  228.     }
  229.     void strings()
  230.     {
  231.         String astring1 = "one";
  232.         String astring2 = "TWO";

  233.         assert((astring1 + "/" + astring2).Equals("one/TWO"));
  234.         assert(astring2.ToLower().Equals("two"));   // Equals ignoring case not available.
  235.         assert(astring1.Length == 3);
  236.         assert(astring1.Substring(0,2).Equals("on"));
  237.         assert(astring1[2] == 'e');
  238.         assert(astring1.ToUpper().Equals("ONE"));
  239.         assert(astring2.ToLower().Equals("two"));
  240.         assert(astring1.CompareTo("p") < 0);
  241.         assert(astring1.IndexOf('e') == 2);
  242.         assert(astring1.IndexOf("ne") == 1);
  243.         assert(astring1.Trim().Length == astring1.Length);

  244.         assert(Char.IsDigit('1'));
  245.         assert(Char.IsLetter('a'));
  246.         assert(Char.IsWhiteSpace('\t'));
  247.         assert(Char.ToLower('A') == 'a');
  248.         assert(Char.ToUpper('a') == 'A');
  249.     }
  250.     private void assert(bool abool)
  251.     {
  252.         if (!abool)
  253.             throw new Exception("assert failed");
  254.     }
  255. }
  256. }
复制代码

Rank: 1

发表于 2011-9-2 09:16:27 |显示全部楼层
dzzyw.net

稀有资源,珍稀资源,尽在代找资源网。

代找源码,软件,游戏,电影,视频,音频,音乐,照片,图片,图纸,文章,文本,等等各种网络资源

专业团队保证找寻能力,最低的价格,最高的效率,最好的跟踪指导.

不管您现在是否需要,都希望您来看看^^

使用道具 举报

Rank: 1

发表于 2011-10-10 14:32:30 |显示全部楼层
上海代办信用卡 上海信用卡办理 上海信用卡代办 上海信用卡代办公司 上海代办信用卡公司 上海办理信用卡 上海高额信用卡代办 上海代办高额信用卡
广州代办信用卡 广州信用卡办理 广州信用卡代办 广州信用卡代办公司 广州代办信用卡公司 广州办理信用卡 广州高额信用卡代办 广州代办高额信用卡
北京信用卡代办中心 在线客服QQ:82629620 公司网站:www.chenxindaiban.com 代办信用卡-信用卡代办-代办信用卡,代办高额信用卡,信用卡代办,信用卡金卡专业代办、信用卡代办公司专业代办信用卡、工行国际卡、招商银行代刷美金港币,全国范围→ 代办信用卡-信用卡金卡代办:办理多家银行信用卡,信用卡透支出来的钱可以长期做生意,可以做为生意的启动资金。

信用卡取现0.5%手续费!

代还信用卡0.8%最低价格欢迎中介合作!!

信用卡的分类:

按发卡组织分:威士卡、万事达卡、美国运通卡、JCB卡、Discover发现卡(美洲)、联合信用卡(台湾)、大来卡、NETS(新加坡)、BC卡(韩国) 、中国银联卡(中国大陆)、(越南)等。威士卡、万事达卡、美国运通卡、JCB卡、大来卡是全球通用的卡。
按币种分:单币卡、双币卡。 公司网站:www.3721db.com
按信用等级分:普通卡(银卡)、金卡、白金卡、无限卡等
按是否联名发行分:联名卡、标准卡(非联名卡),认同卡。

本公司安全专业代办信用卡-代办白金卡-代办金卡-代办高额信用卡,包工作证明(办500强的厂证)、收入证明,银行工资发放流水记录,事业单位水、电、煤等住址证明,代办财力证明,走银行绿色通道办理,公司设有专人接银行电话,并与各银行的业务经理、审卡中心审核员合作,一条龙式办卡(全国均可办理。一张身份证可同时办理14家银行的信用卡(中信,农行,建行,中行,兴业,民生,华夏,光大,广发,深发,交通,招商,工行),可以为持本人身份证的全国任何18周岁以上的人代办理高额金卡,直接交卡中心审批,100%包下卡 !
在中国代办的外国信用卡:


目前,可在中国代办的外国信用卡主要有:1、万事达卡(Master Card)。2、维萨卡(Vise Card)。3、运通卡(American Express Card)。4、JCB卡。5、大莱卡(Diners Card)。
办理信用卡好处:
信用卡可作为一时资金周转所用或作为您其他的投资消费项目!
1、先消费后还款,享受最长56天的免息还款期。
2、选择最低还款额还款,享受银行循环信用。
3、信用额度高(5000-50万元),让您尽情享受现代都市生活。一朝办理,终身受益。
4、 信誉好,下卡快,易批核,,为您轻松理财!
5、下卡额度高!没有工作的朋友也可以办理!
6、为拥有信用卡的客户提供方便快捷的现金即刷即提。
7、我们具有最专业的信用卡知识,使您的信用卡达到最好的使用率,合理利用最长免息期,努力提升您的 信用度!使您一朝办理,终身受益
诚信+快速专业代办白金卡
公司网站:www.3721db.com
公司承诺:规定时间内信用卡代办没下卡,公司赔偿双倍代办费。现在办理信用卡,公司即送壹年信用卡年费 上 海 信 用 卡 代 办 公 司 在线客服QQ:82629620 联系 张先生

 

使用道具 举报

您需要登录后才可以回帖 登录 | 注册