Original Address https://www.cnblogs.com/younShieh/p/10945264.html
A few days ago in the brush immediately I found a project on GitHub, the project called "learn x in y minutes", the name is very concise - "y minutes learning xxx", a look at the very cattle. For this the god-level characters I was very vision of a feeling of joy and awe of mind, point down the star, and then I took off the page. . . Do not ask me why not learn about hot, after all, we all know, the collection is equivalent to learn a thing.
n days after today, I finally remembered to have such a great project still lying on my list, I took it turned out, learn about the project in the c # documentation. He did not disappoint, very productive. As the authors put it:
Code documentation written as code! How novel and totally my idea!
It is indeed strange to explain the method, several hundred lines of code to put a lot of C # common basic grammar he told over and over, and in the form of code, not long-winded, speak in code syntax is the most intuitive. But I do not think for beginners, or for people who have some foundation, or one can not read, there is no interpretation, can not be put in the heart of hammering a dozen times.
Ado, Project address: https: //github.com/adambard/learnxinyminutes-docs
The project in the c # code, there are some simple questions at run-time, I was given a free hand to modify. The revised code attached to the end of the article.
Share this document and the project, and hope you can help me as a novice.
// 单行注释以 // 开始
/*
多行注释是这样的
*/
/// <summary> /// XML文档注释 /// </summary> // 声明应用用到的命名空间 using System; using System.Collections.Generic; using System.Data.Entity; using System.Dynamic; using System.IO; using System.Linq; using System.Net; using System.Threading.Tasks; // 定义作用域,将代码组织成包 namespace Learning { // 每个 .cs 文件至少需要包含一个和文件名相同的类 // 你可以不这么干,但是这样不好。 public class LearnCSharp { // 基本语法 - 如果你以前用过 Java 或 C++ 的话,可以直接跳到后文「有趣的特性」 public static void Syntax() { // 使用 Console.WriteLine 打印信息 Console.WriteLine("Hello World"); Console.WriteLine( "Integer: " + 10 + " Double: " + 3.14 + " Boolean: " + true); // 使用 Console.Write 打印,不带换行符号 Console.Write("Hello "); Console.Write("World"); // 字符串 -- 和前面的基本类型不同,字符串不是值,而是引用。 // 这意味着你可以将字符串设为null。 string fooString = "\"escape\" quotes and add \n (new lines) and \t (tabs)"; Console.WriteLine(fooString); // 你可以通过索引访问字符串的每个字符: char charFromString = fooString[1]; // => 'e' // 字符串不可修改: fooString[1] = 'X' 是行不通的; // 根据当前的locale设定比较字符串,大小写不敏感 string.Compare(fooString, "x", StringComparison.CurrentCultureIgnoreCase); // 基于sprintf的字符串格式化 string fooFs = string.Format("Check Check, {0} {1}, {0} {1:0.0}", 1, 2); // 日期和格式 DateTime fooDate = DateTime.Now; Console.WriteLine(fooDate.ToString("hh:mm, dd MMM yyyy")); /////////////////////////////////////////////////// // 数据结构 /////////////////////////////////////////////////// // 数组 - 从0开始计数 // 声明数组时需要确定数组长度 // 声明数组的格式如下: // <datatype>[] <var name> = new <datatype>[<array size>]; int[] intArray = new int[10]; // 声明并初始化数组的其他方式: int[] y = { 9000, 1000, 1337 }; // 访问数组的元素 Console.WriteLine("intArray @ 0: " + intArray[0]); // 数组可以修改 intArray[1] = 1; // 列表 // 列表比数组更常用,因为列表更灵活。 // 声明列表的格式如下: // List<datatype> <var name> = new List<datatype>(); List<int> intList = new List<int>(); List<string> stringList = new List<string>(); List<int> z = new List<int> { 9000, 1000, 1337 }; // i // <>用于泛型 - 参考下文 // 列表无默认值 // 访问列表元素时必须首先添加元素 intList.Add(1); Console.WriteLine("intList @ 0: " + intList[0]); // 其他数据结构: // 堆栈/队列 // 字典 (哈希表的实现) // 哈希集合 // 只读集合 // 元组 (.Net 4+) /////////////////////////////////////// // 操作符 /////////////////////////////////////// Console.WriteLine("\n->Operators"); int i1 = 1, i2 = 2; // 多重声明的简写形式 // 算术直截了当 Console.WriteLine(i1 + i2 - i1 * 3 / 7); // => 3 // 取余 Console.WriteLine("11%3 = " + (11 % 3)); // => 2 // 比较操作符 Console.WriteLine("3 == 2? " + (3 == 2)); // => false Console.WriteLine("3 != 2? " + (3 != 2)); // => true Console.WriteLine("3 > 2? " + (3 > 2)); // => true Console.WriteLine("3 < 2? " + (3 < 2)); // => false Console.WriteLine("2 <= 2? " + (2 <= 2)); // => true Console.WriteLine("2 >= 2? " + (2 >= 2)); // => true // 位操作符 /* ~ 取反 << 左移(有符号) >> 右移(有符号) & 与 ^ 异或 | 或 */ // 自增、自减 int i = 0; Console.WriteLine("\n->Inc/Dec-rementation"); Console.WriteLine(i++); //i = 1. 事后自增 Console.WriteLine(++i); //i = 2. 事先自增 Console.WriteLine(i--); //i = 1. 事后自减 Console.WriteLine(--i); //i = 0. 事先自减 /////////////////////////////////////// // 控制结构 /////////