c#中的分部类和分部方法

1c#语言是经过两次编译的由源代码编译为微软中间语言然后在编译为机器语言有jit完成最后的编译

2进制转换函数convert.toInt32(“1110011”,2)将2进制转换为10进制数,对于8或是16进制数转换为10进制时用法相同

同样10进制数转换为2,8,16进制数时使用convert.tostring(89,2);将89转换为2进制数同样可以修改基数2 将其转化为8 或16进制数

冒泡法,快速排序发,费波那歇数列

3索引器的使用目的就是为了访问类中的数组或是集合类 的成员变量,对应私有的数组或是集合类的成员变量不能直接访问,但如果在java中可以使用访问器遍历即可。但是在c#中没有针对数组或集合对象的访问器,只能使用索引器啦使用格式如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace index_solution

{

    class index

    {

        static void Main(string[] args)

        {

            TestClass tc = new TestClass();

            tc[0] = "grubby";

            tc[1] = "moon";

            tc[2] = "sky";

            for (int i = 0; i < 3;i++ )

            {

                Console.WriteLine(tc[i]);

            }

        }

    }

    class TestClass

    {

        private string[] student = new string[3];

        public string this[int studentNo]

        {

            get

            {

                return student[studentNo];

            }

            set

            {

                student[studentNo] = value;

            }

        }

    }

}

在访问多维数组时索引器可以有多个形参,利用多个形参来依次遍历多维数组的元素。

属性可以是静态的但是索引器必须为实例成员。

索引器的属性名统一为this不能是其他专门用于定义索引器

索引器要求必须用唯一是索引器签名,而属性要求必须有唯一的属性名。

4分部类目的是在项目较大时有多个人编写同一个类使用关键字partial使用如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace index_solution

{

    class index

    {

        static void Main(string[] args)

        {

            car car = new car();

            Console.WriteLine(car.doSomething2());

            Console.WriteLine(car.doSomething1());

           

        }

    }

    class TestClass

    {

        private string[] student = new string[3];

        public string this[int studentNo]

        {

            get

            {

                return student[studentNo];

            }

            set

            {

                student[studentNo] = value;

            }

        }

    }

}

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace index_solution

{

   partial class car

    {

        public string doSomething1()

        {

            return "doSomething 1";

        }

    }

}

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace index_solution

{

     partial class car

    {

         public string doSomething2()

         {

             return "dosomething 2";

         }

    }

}

 

5分布方法的作用是有多个人分别编写同一个分布类中的多个方法,这样只要在分布类中存在对分布方法的声明,就可以在分布类中调用分布方法,分布方法可以在同一个分布类的多个分布文件中声明,定义其实现。即声明,和实现是在不同的分布类文件中,但是在同一个分布类中。

         分布方法的要求:

         使用关键字partial

         声明不能使用修饰符,因此是隐式私有的,不能在类外被访问,只能被本类访问

         不能有返回值只能是void类型,就是说只能实现功能的实现不能利用其返还任何值

         声明和定义最好是使用一致的方法签名

         可以有ref参数,不能有out参数

如果分布方法没有被实现,那么程序中所有调用分布方法的地方都会在编译时被自动移除,分布方法的声明也会被移除,编译器不会报错。

使用格式如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace index_solution

{

    class FBTest

    {

        static void Main(string[] args)

        {

            FBClass fbclass = new FBClass();

            Console.WriteLine(fbclass.doSomething1());

            Console.WriteLine(fbclass.doSomething3());

           

        }

       

       

       

       

    }

}

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace index_solution

{

    partial class FBClass

    {

        public string doSomething1()

        {

            return "dosomething1()";

        }

        partial void doSomething2(string sth);

 

    }

}

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace index_solution

{

     partial class FBClass

    {

         public string doSomething3()

         {

             doSomething2("dosomething2()");

             return "dosomething3()";

         }

         partial void doSomething2(string sth)

         {

             Console.WriteLine(sth);

         }

    }

}

注释的xml注释格式

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Genersoft.Platform.XFormController;

using Genersoft.Platform.Resource;

using Genersoft.Platform.Core;

using Genersoft.Platform.XFormController.FormController;

using Genersoft.Platform.XForm.SPI;

using Genersoft.Platform.Resource.Metadata.Component.Attributes;

 

namespace TestDemo

{

    public class TestDemo:SingleController

    {

        public TestDemo(IFormActionContext formContext)

            : base(formContext)

        { 

        }

        ///<summary>

        ///the method of instance

        ///<summary>

        ///<param name="message">the information to show </param>

        [ControllerMethod]

        [ControllerFormalParameter("message", true)]

       /// <summary>

       /// 

       /// </summary>

       /// <param name="message"></param>

       /// <returns></returns>

        public void HelloWorld(string message)

        {

            this.CompContext.ShowInfo("hello "+message);

        }

        

    }

}

 

 

2

 

 

 

原文地址:https://www.cnblogs.com/moonfans/p/2787404.html