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注释格式

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Text;

usingGenersoft.Platform.XFormController;

usingGenersoft.Platform.Resource;

usingGenersoft.Platform.Core;

usingGenersoft.Platform.XFormController.FormController;

usingGenersoft.Platform.XForm.SPI;

usingGenersoft.Platform.Resource.Metadata.Component.Attributes;

namespaceTestDemo

{

publicclassTestDemo:SingleController

{

publicTestDemo(IFormActionContextformContext)

:base(formContext)

{

}

///<summary>

///themethodofinstance

///<summary>

///<paramname="message">theinformationtoshow</param>

[ControllerMethod]

[ControllerFormalParameter("message",true)]

///<summary>

///

///</summary>

///<paramname="message"></param>

///<returns></returns>

publicvoidHelloWorld(stringmessage)

{

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

}

}

}

2

优质内容筛选与推荐>>
1、怎么在ASP.NET 2.0中使用Membership
2、与众不同 windows phone (37) - 8.0 文件系统: StorageFolder, StorageFile, 通过 Uri 引用文件, 获取 SD 卡中的文件
3、java.util.Date
4、PHP之cURL
5、angular2 基于webpack环境搭建


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号