zoukankan      html  css  js  c++  java
  • 第一个C#程序.

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace OneCshapApplication
     7 {
     8     class Program
     9     {
    10         static void Main(string[] args)
    11         {
    12             //定义几个变量,
    13             int age;  //整形
    14             string Name;  //字符串型
    15             string Gender;
    16 
    17             Console.WriteLine("先输出一句Hello Wolrd!");
    18             Console.Write("请输入您的姓名:"); //输出语句,不自动添加换行符
    19             Name = Console.ReadLine();  //Console.ReadLine(); 输入语句,输入一行自动添加换行符
    20             Console.Write("请输入的您的年龄:"); 
    21             age = Convert.ToInt32(Console.ReadLine()); //字符串转换整形
    22             Console.Write("请输入您的性别:");  
    23             Gender = Console.ReadLine();
    24             Console.WriteLine("您的姓名是:{0} 您的年龄是:{1} 您的性别是:{2}",Name,age,Gender+ "\n 您确定信息无误吗?");  //这里面的\n是转义字,代表插入一个换行符
    25             ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    26 
    27             //进制转换.
    28             Console.WriteLine("进制转换");
    29             //十进制转二进制
    30             Console.WriteLine(Convert.ToString(69, 2)); //结果等于1000101
    31             //十进制转八进制
    32             Console.WriteLine(Convert.ToString(69, 8)); //等于105
    33             //十进制转十六进制
    34             Console.WriteLine(Convert.ToString(69, 16)); // 等于45
    35             //二进制转十进制
    36             Console.WriteLine(Convert.ToInt32("100111101", 2)); // 等于317
    37             //八进制转十进制
    38             Console.WriteLine(Convert.ToInt32("76", 8)); //等于62
    39             //C# 16进制转换10进制
    40             Console.WriteLine(Convert.ToInt32("FF", 16)); // 等于255
    41         }
    42     }
    43 }

    //在该代码中,会发现ToInt32这个函数用在了两个不同的地方. 其实在C#中,很多函数都有多种功能. 慢慢消化吧.
  • 相关阅读:
    HDU 4278 Faulty Odometer 8进制转10进制
    hdu 4740 The Donkey of Gui Zhou bfs
    hdu 4739 Zhuge Liang's Mines 随机化
    hdu 4738 Caocao's Bridges tarjan
    Codeforces Gym 100187M M. Heaviside Function two pointer
    codeforces Gym 100187L L. Ministry of Truth 水题
    Codeforces Gym 100187K K. Perpetuum Mobile 构造
    codeforces Gym 100187J J. Deck Shuffling dfs
    codeforces Gym 100187H H. Mysterious Photos 水题
    windows服务名称不是单个单词的如何启动?
  • 原文地址:https://www.cnblogs.com/mdnx/p/2653299.html
Copyright © 2011-2022 走看看