C#之引用 ref

来源:互联网 发布:网站建设优化公司 编辑:程序博客网 时间:2024/05/20 17:07

目前没有深究,和c++用法一样,在代码编写过程中发现,在主函数之外写函数需要声明成为static类型的,否则编译不通过,真是蛋疼

using System;using System.Text;namespace Excise1{    public class Program    {        public class Student        {            private int age;            private string name;            private string id;            public int Age            {                get                {                    return age;                }                set                {                    age = value;                }            }            public string Name            {                get                {                    return name;                }                set                {                    name = value;                }            }            public string ID            {                get                {                    return id;                }                set                {                    id = value;                }            }        }                  static void swap(ref int a, ref int b)            {                int temp;                temp = a;                a = b;                b = temp;            }                     public static void Main(string[] args)        {            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);            int a = 5;            int b = 10;                   swap(ref a,ref b);            Console.WriteLine(" a=" + a + " b=" + b);                                     Console.ReadKey();         }    }}


0 0