zoukankan      html  css  js  c++  java
  • C# 图解教程 第二章 C#编程概述

    C#编程概述

    一个简单的C#程序


    标识符


    标识符是一种字符串,用来命名变量、方法、参数和许多后面将要阐述的其他程序结构。

    关键字


    所有C#关键字都由小写字母组成,但是.NET类型名使用Pascal大小写约定。


    Main:程序的起始点


    • C#程序的可执行起始点在Main中第一条指令
    • Main首字母必须大写

    从程序输出文本


    BCL(Base Class Library,基类库)提供Console类(在System命名空间中),该类包含了输入和输出数据到控制台的方法。 
    Write

    Console.Write("This is trivial text.");

     
    WriteLine

    System.Console.WriteLine("This is text1.");
    System.Console.WriteLine("This is text2.");
    System.Console.WriteLine("This is text3.");

     
    格式字符串

    Console.WriteLine("Two sample integers are {0} and {1}.",3,6);

     
    多重标记和值

    Console.WriteLine("Three integers are {1},{0} and {1}.",3,6);

     
    格式化数字字符串

    Console.WriteLine("The value:{0}.",500);
    Console.WriteLine("The value:{0:C}.",500);

    对齐说明符

    int myInt=500;
    Console.WriteLine("|{0,10}|",myInt);
    Console.WriteLine("|{0,-10}|",myInt);

    格式字段


    double myDouble=12.345678;
    Console.WriteLine("{0,-10:G}--General", myDouble);
    Console.WriteLine("{0,-10}--Default,same as General", myDouble);
    Console.WriteLine("{0,-10:F4}--Fixed Point,4 dec places", myDouble);
    Console.WriteLine("{0,-10:C}--Currency", myDouble);
    Console.WriteLine("{0,-10:E3}--Sci.Notation,3 dec places", myDouble);
    Console.WriteLine("{0,-10:x}--Hexadecimal integer",1194719);

    标准数字格式说明符


    注释




    from: http://www.cnblogs.com/moonache/p/5995909.html

  • 相关阅读:
    hdu4998 旋转坐标系
    hdu4998 旋转坐标系
    hdu5012 水搜索
    hdu5012 水搜索
    hdu5007 小水题
    ZOJ 3645 BiliBili 高斯消元 难度:1
    ZOJ 3654 Letty's Math Class 模拟 难度:0
    ZOJ 3647 Gao the Grid dp,思路,格中取同一行的三点,经典 难度:3
    ZOJ 3646 Matrix Transformer 二分匹配,思路,经典 难度:2
    ZOJ 3644 Kitty's Game dfs,记忆化搜索,map映射 难度:2
  • 原文地址:https://www.cnblogs.com/GarfieldEr007/p/10126543.html
Copyright © 2011-2022 走看看