您的位置:首页 > 其它

从零开始把一些简单的不易理解的记录下来。

2012-04-01 16:21 295 查看
int.Parse("a");//当不是数字,或者比int.maxvalue大时,会报错
int.TryParse("aaa",out b);//如果是字符串,或者比int大,则返回0,不会报错

int number;//在这给值没有用的
number = Test(out number);//输出值

 static int Test(out int a)//输出值
        {
            a = 200;//在方法里面一定要给值
            return a;//
        }



out 传出值,ref为址传递,会改变值

static void Main(string[] args)
        {

            int a = 11;
            int b = 22;
            int c = 33, d = 44;
            Change(ref a, ref b);
            Change(c,d);
            Console.WriteLine("a的值={0},b的值={1}",a,b);
            Console.WriteLine("c的值={0},d的值={1}", c, d);
            Console.ReadKey();
        }

        static void Change(ref int a,ref int b)
        {
            int temp = a;
            a = b;
            b = temp;
          
        }
        static void Change( int a,  int b)
        {
            int temp = a;
            a = b;
            b = temp;

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: