• C#_基本类型


    1、C#中的值类型包括:简单类型、枚举类型和结构类型。

    2、C#中的引用类型包括:类(class)、接口(interface)、数组、委托(delegate)、object和string。

    3、调试时想要停留在控制台操作: Console.Readline();

        字符串强制转换成int型:Convert.ToInt32(Console.ReadLine());

       或者如下表示:

        string s = Console.ReadLine();
        int Grate = Convert.ToInt32(s);

    4、Console.Readline();    : 控制台接受输入的一个字符串。

        Console.Read();          :控制台接受输入的一个字符。

        a.GetLength(1)            :a数组第二维的长度。

        a.Length                     : a数组的总体长度,即元素总个数,与它的维数无关。

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace MaxMin
     7 {
     8     class Program
     9     {
    10         static void Main(string[] args)
    11         {
    12             int max, min;
    13             int[] queue = new int[10];//{ 89, 76, 64, 3, 31, 62, 0, 91, 100, 21 };
    14             Console.WriteLine("请输入十个数到数组中:
    ");
    15             for (int i = 0; i < queue .Length; i++)
    16             {
    17                 queue[i] = Convert.ToInt32(Console.ReadLine());
    18             }
    19             for (int i = 0; i < 10; i++)
    20             {
    21                 Console.Write("{0,5}",queue[i]);
    22             }
    23             Console.WriteLine("
    ");
    24             max = min = queue[0];
    25             for (int i = 1; i < 10; i++)
    26             {
    27                 if (max < queue[i])
    28                 {
    29                     max = queue[i];
    30                 }
    31                 if (min > queue[i])
    32                 {
    33                     min = queue[i];
    34                 }
    35             }
    36             Console.WriteLine("最大数是{0},
    最小数是{1}", max, min);
    37         }
    38     }
    39 }
    View Code

     5、产生随机数:

                Random Rnd = new Random();
                int k;
                k = Rnd.Next(50);// 产生0到52之间的随机数
  • 相关阅读:
    过滤非GBK字符
    打印整数数字
    std::string 方法列表
    设计模式——单例模式(Singleton )
    编程之美二进制一的个数
    Jsoncpp试用指南
    GCC下宏扩展后的++i
    关于字节对齐的sizeof的讨论
    Notepad++ 更改和定制主题
    求子数组的最大和
  • 原文地址:https://www.cnblogs.com/chensup/p/5818755.html
Copyright © 2020-2023  润新知