交换两个变量的值

本文介绍了使用C#语言进行编程的基础概念与实践案例,包括变量操作、数值运算、字符串处理、文件路径获取、字符串转换、自增运算符、递归函数调用、静态与非静态方法、内存优化特性等核心知识点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
  class Program
    {
        static void Main()
        {
            //int a = 2, b = 3;
            ////二进制    10,11
            //a = a ^ b;    //a = 01 也就是1  b = 11
            //b = a ^ b;   //b = 10
            //a = a ^ b;// a = 11

            //Console.WriteLine(a);
            //Console.ReadLine();

            //int a = 5369;//实现两次乘以2
            //编译器 将a转化成2进制  1010011111001
            //乘以2 对于2进制 就是后面加 0
            //结果 101001111100100  = a * 2


            //string path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            //Console.WriteLine(path);

            //string a = changeValue(2147483647, 2);
            //Console.WriteLine(a);


            //int i = 10;
            //int b = i++ + i++ + i++;
            //Console.WriteLine("b={0},i={1}",b,i);

            //i = 1;
            //i = i++;
            //int b = i++;
            //Console.WriteLine(i);
            //Console.WriteLine(b);
            //i = 1;          
            //int b = ++i;
            //int c = i++;

            //int count = 0;
            //Test(0, ref count, 100);
            //Console.WriteLine(count);
            //Console.ReadLine();
            ////静态方法是属于类的
            ////非静态方法是属于对象的
            ////Program p = new Program();
            ////p.Test2(0, ref count, 100);
            //Environment.Exit(0);


        }

        //private static void Test(int index, ref int count, int i)
        //{
        //    if (index < i)
        //    {
        //        index++;
        //        count += index;
        //        Test(index, ref count, i);
        //    }
        //    else
        //    {
        //        return;
        //    }

        //}



        //private void Test2(int index, ref int count, int i)
        //{
        //    if (index < i)
        //    {
        //        index++;
        //        count += index;
        //        Test(index, ref count, i);
        //    }
        //    else
        //    {
        //        return;
        //    }

        //}

        //private static string changeValue(int a, int b)
        //{
        //    string ret = string.Format("a=[{0}],b = [{1}]", a, b) + Environment.NewLine;
        //    //a = a + b;
        //    //b = a - b;
        //    //a = a - b;
        //编译器自动优化的特点
        //    a = b + (b = a) * 0;


        //    ret += string.Format("new a=[{0}], new b = [{1}]", a, b) + Environment.NewLine;

        //    return ret;
        //}


    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值