c#笔记2018-12-26

using System;
/*C#学习笔记2018-12-26
 * 1.@逐字字符串
 * 2.数据类型转换
 * 3.变量声明和占位符使用
 * 4.接收用户输入值
 * 5.const 关键字
 * 6.运算符
 * 7.三元运算符
 */
namespace Csharp_study
{
    class section1
    {
        static void Main(string[] args)
        {
            //1.@逐字字符串
            string str1 = "
";//
将会被当做转义字符处理
            string str2 = @"
";//使用@在字符串之前该字符串将不会被转义

            //2.数据类型转换
            //显式--强制数据类型转换
            float f1=12.3f;
            int i1 = (int)f1;
            //隐式--安全的数据类型转换
            char a = 'A';
            string b = a.ToString();

            //3.变量的声明和占位符的使用  
            int i = 0, j = 1, o = 4;

            //4.接收用户输入的值
            int num;
            Console.WriteLine("请输入一个整数:");
            num = Convert.ToInt32(Console.ReadLine());

            //5.const 关键字
            const  double pi=3.1415;
            //pi = 3.3;无法再给常量赋值,此处会报错

            //6.运算符
            //省略算数运算符+、-、*、/、%、++、--
            //逻辑运算符&&与、||或、!非
            if ((1 == 1) && (2 == 2)){
                Console.WriteLine("与运算---有假为假");
            }else {
                ;
            }
            if((1==1)||(0==1)){
                Console.WriteLine("或运算---有真为真");
            }else
            {
                ;
            }

            //7.三元运算符
            //(条件)?值1:值2  条件为true时 表达式值为1  条件为false时 表达式值为2
            int aa = 1;
            int bb;
            bb = (aa==1)?10:20;
            Console.WriteLine("bb的值是{0}",bb);

            //控制台输出
            Console.WriteLine(str1);
            Console.WriteLine(str2);
            Console.WriteLine(b);
            Console.WriteLine(i1);
            Console.WriteLine("i:{0},j:{1},i+j:{2}",i,j,o);
            Console.WriteLine("您输入的整数是:" + num.ToString());
            Console.WriteLine(pi);
            Console.ReadKey();
        }
    }
}

  

原文地址:https://www.cnblogs.com/soulsjie/p/10181762.html