全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 winbugs及其他软件专版
1606 4
2015-06-01

  • C# Cookbook, Second Edition
  • By: Jay Hilyard; Stephen Teilhet

  • Publisher: O'Reilly Media, Inc.

  • Pub. Date: January 30, 2006   Most Recent Edition

  • Print ISBN-13: 978-0-596-10063-6

  • Print ISBN-10: 0-596-10063-9

  • Pages in Print Edition: 1192

  • Subscriber Rating: [0 Ratings]



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-6-1 06:46:35
Recipe 3.1. Creating Union-Type Structures
Problem
You need to create a data type that behaves like a union type in C++. A union type is useful mainly in interop scenarios in which the unmanaged code accepts and/or returns a union type; we suggest that you do not use it in other situations.

Solution
Use a structure and mark it with the StructLayout attribute (specifying the LayoutKind.Explicit layout kind in the constructor). In addition, mark each field in the structure with the FieldOffset attribute. The following structure defines a union in which a single signed numeric value can be stored:

复制代码

复制代码

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-6-1 06:49:03
Recipe 3.2. Allowing a Type to Represent Itself as a String
Problem
Your class or structure needs to control how its information is displayed when its ToString method is called. In addition, you need to apply different formats to this information. For example, when creating a new data type, such as a Line class, you might want to allow objects of this type to be able to display themselves in a textual format. In the case of a Line object, it might display itself as (x1, y1)(x2, y2).

Solution
Override and/or implement the IFormattable.ToString method to display numeric information, such as for a Line structure:

复制代码

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-6-1 06:52:22
Recipe 3.3. Converting a String Representation of an Object into an Actual Object
Problem
You need a way of accepting a string containing a textual representation of an object and converting it to an object usable by your application. For example, if you were provided with the string representation of a line (x1, y1)(x2, y2), you would want to convert it into a Line structure.

Solution
Implement a Parse method on your Line structure:
复制代码
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-6-6 13:20:38
hao shu
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群