
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
	<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head><card id="MainCard" title="&#x6B22;&#x8FCE;&#x5149;&#x4E34;"><p><a href="wap.asp">&#x6728;&#x5B50;&#x5C4B;</a><br/>&nbsp;</p><p><b>&#x6807;&#x9898;&#x3A;</b> &#x45;&#x66;&#x66;&#x65;&#x63;&#x74;&#x69;&#x76;&#x65;&#x20;&#x43;&#x23;&#x20;&#x539F;&#x5219;&#x38;&#xFF1A;&#x786E;&#x4FDD;&#x30;&#x5BF9;&#x4E8E;&#x503C;&#x7C7B;&#x578B;&#x6570;&#x636E;&#x662F;&#x6709;&#x6548;&#x7684;</p><p><b>&#x4F5C;&#x8005;&#x3A;</b> &#x64;&#x6E;&#x61;&#x77;&#x6F;</p><p><b>&#x65E5;&#x671F;&#x3A;</b> &#x32;&#x30;&#x30;&#x39;&#x2D;&#x30;&#x36;&#x2D;&#x30;&#x32;&#x20;&#x30;&#x39;&#x3A;&#x31;&#x35;&#x20;&#x50;&#x4D;</p><p><b>&#x5206;&#x7C7B;&#x3A;</b> <a href="wap.asp?do=showLog&amp;cateID=5">&#x57;&#x65;&#x62;&#x7F16;&#x7A0B;</a></p><p><b>&#x5185;&#x5BB9;&#x3A;</b> .Net&#x7CFB;&#x7EDF;&#x9ED8;&#x8BA4;&#x6240;&#x6709;&#x7684;&#x5BF9;&#x8C61;&#x521D;&#x59CB;&#x5316;&#x65F6;&#x90FD;&#x4E3A;0&#x3002;&#x8FD9;&#x5E76;&#x6CA1;&#x6709;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x6765;&#x9884;&#x9632;&#x5176;&#x4ED6;&#x7A0B;&#x5E8F;&#x5458;&#x521B;&#x5EFA;&#x7684;&#x503C;&#x7C7B;&#x578B;&#x6570;&#x636E;&#x7684;&#x5B9E;&#x4F8B;&#x5728;&#x521D;&#x59CB;&#x5316;&#x662F;&#x90FD;&#x662F;0&#x3002;&#x8BF7;&#x8BA9;&#x4F60;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x9ED8;&#x8BA4;&#x503C;&#x4E5F;&#x662F;0&#x3002;<br/>&#x4E00;&#x4E2A;&#x7279;&#x6B8A;&#x60C5;&#x51B5;&#x662F;&#x5728;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x6570;&#x636E;&#x4E2D;&#x3002;&#x51B3;&#x4E0D;&#x8981;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x4E0D;&#x5305;&#x62EC;0&#x5728;&#x5185;&#x7684;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x3002;&#x6240;&#x6709;&#x7684;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x90FD;&#x662F;&#x4ECE;System.ValueType&#x6D3E;&#x751F;&#x7684;&#x3002;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x7684;&#x503C;&#x662F;&#x4ECE;0&#x5F00;&#x59CB;&#x7684;&#xFF0C;&#x4F46;&#x4F60;&#x53EF;&#x4EE5;&#x6539;&#x53D8;&#x8FD9;&#x4E00;&#x884C;&#x4E3A;&#xFF1A;<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;public enum Planet<br/>{<br/>&nbsp;&nbsp;// Explicitly assign values.<br/>&nbsp;&nbsp;// Default starts at 0 otherwise.<br/>&nbsp;&nbsp;Mercury = 1,<br/>&nbsp;&nbsp;Venus = 2,<br/>&nbsp;&nbsp;Earth = 3,<br/>&nbsp;&nbsp;Mars = 4,<br/>&nbsp;&nbsp;Jupiter = 5,<br/>&nbsp;&nbsp;Saturn = 6,<br/>&nbsp;&nbsp;Neptune = 7,<br/>&nbsp;&nbsp;Uranus = 8,<br/>&nbsp;&nbsp;Pluto = 9<br/>}<br/>Planet sphere = new Planet();<br/>sphere&#x6B64;&#x65F6;&#x7684;&#x503C;&#x5C31;&#x662F;0&#xFF0C;&#x800C;&#x8FD9;&#x5E76;&#x4E0D;&#x662F;&#x4E00;&#x4E2A;&#x6709;&#x6548;&#x7684;&#x503C;&#x3002;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x7684;&#x53D6;&#x503C;&#x9650;&#x5236;&#x5728;&#x6240;&#x6709;&#x5217;&#x4E3E;&#x7684;&#x503C;&#x4E2D;&#xFF0C;&#x4EFB;&#x4F55;&#x4F9D;&#x61D2;&#x8FD9;&#x4E00;(&#x666E;&#x901A;)&#x4E8B;&#x5B9E;&#x7684;&#x4EE3;&#x7801;&#x90FD;&#x5C06;&#x65E0;&#x6CD5;&#x5DE5;&#x4F5C;&#x3002;&#x5F53;&#x4F60;&#x4E3A;&#x4F60;&#x7684;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x521B;&#x5EFA;&#x4F60;&#x81EA;&#x5DF1;&#x7684;&#x53D6;&#x503C;&#x65F6;&#xFF0C;&#x8BF7;&#x786E;&#x4FDD;0&#x662F;&#x5F53;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x3002;&#x5982;&#x679C;&#x4F60;&#x7684;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x91C7;&#x7528;&#x7684;&#x662F;&#x4EE5;&#x4F4D;(bit)&#x6A21;&#x5F0F;&#xFF0C;&#x628A;0&#x5B9A;&#x4E49;&#x4E3A;&#x5176;&#x5B83;&#x5C5E;&#x6027;&#x4E0D;&#x5B58;&#x5728;&#x65F6;&#x7684;&#x53D6;&#x503C;&#x3002;<br/>&#x6309;&#x7167;&#x73B0;&#x5728;&#x7684;&#x60C5;&#x51B5;,&#x4F60;&#x8FEB;&#x4F7F;&#x7528;&#x6237;&#x5FC5;&#x987B;&#x7CBE;&#x786E;&#x7684;&#x521D;&#x59CB;&#x5316;&#x503C;&#xFF1A;<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;Planet sphere = Planet.Mars;<br/>&#x8FD9;&#x5C06;&#x4F7F;&#x5305;&#x542B;(Planet)&#x8FD9;&#x4E00;&#x7C7B;&#x578B;&#x7684;&#x5176;&#x5B83;&#x7C7B;&#x578B;&#x5F88;&#x96BE;&#x521B;&#x5EFA;&#xFF1A;<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;public struct ObservationData<br/>{<br/>&nbsp;&nbsp;Planet&nbsp;&nbsp; _whichPlanet; //what am I looking at?<br/>&nbsp;&nbsp;Double&nbsp;&nbsp;_magnitude; // perceived brightness.<br/>}<br/>&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;ObservationData&#x5B9E;&#x4F8B;&#x7684;&#x7528;&#x6237;&#x4F1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x4E0D;&#x5408;&#x6CD5;&#x7684;Planet&#x6210;&#x5458;&#xFF1A;<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;ObservationData d = new ObservationData();<br/>&#x6700;&#x540E;&#x521B;&#x5EFA;&#x7684;ObservationData&#x7684;&#x6210;&#x5458;_magnitude&#x7684;&#x503C;&#x662F;0&#xFF0C;&#x8FD9;&#x662F;&#x5408;&#x7406;&#x7684;&#x3002;&#x4F46;_whichPlanet&#x5374;&#x662F;&#x65E0;&#x6548;&#x7684;&#x3002;&#x4F60;&#x987B;&#x8981;&#x8BA9;0&#x4E5F;&#x662F;&#x6709;&#x6548;&#x7684;(&#x72B6;&#x6001;)&#x3002;&#x5982;&#x679C;&#x53EF;&#x80FD;&#xFF0C;&#x9009;&#x62E9;&#x628A;0&#x505A;&#x4E3A;&#x4E00;&#x4E2A;&#x6700;&#x597D;&#x7684;&#x9ED8;&#x8BA4;&#x3002;Planet&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x6CA1;&#x6709;&#x4E00;&#x4E2A;&#x660E;&#x786E;&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x65E0;&#x8BBA;&#x7528;&#x6237;&#x662F;&#x5426;&#x4EFB;&#x610F;&#x7684;&#x9009;&#x62E9;&#x4E00;&#x4E9B;&#x884C;&#x661F;&#xFF0C;&#x8FD9;&#x90FD;&#x4E0D;&#x4F1A;&#x7ED9;&#x4EBA;&#x7559;&#x4E0B;&#x597D;&#x7684;&#x611F;&#x89C9;&#x3002;&#x5F53;&#x4F60;&#x9677;&#x5165;&#x8FD9;&#x6837;&#x7684;&#x60C5;&#x51B5;&#x65F6;&#xFF0C;&#x4F7F;&#x7528;0&#x505A;&#x4E3A;&#x4E00;&#x4E2A;&#x975E;&#x521D;&#x59CB;&#x5316;&#x7684;&#x503C;&#xFF0C;&#x8FD9;&#x4E5F;&#x662F;&#x5728;&#x540E;&#x9762;&#x53EF;&#x4EE5;&#x66F4;&#x65B0;&#x7684;&#xFF1A;<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;public enum Planet<br/>{<br/>&nbsp;&nbsp;None = 0,<br/>&nbsp;&nbsp;Mercury = 1,<br/>&nbsp;&nbsp;Venus = 2,<br/>&nbsp;&nbsp;Earth = 3,<br/>&nbsp;&nbsp;Mars = 4,<br/>&nbsp;&nbsp;Jupiter = 5,<br/>&nbsp;&nbsp;Saturn = 6,<br/>&nbsp;&nbsp;Neptune = 7,<br/>&nbsp;&nbsp;Uranus = 8,<br/>&nbsp;&nbsp;Pluto = 9<br/>}<br/>Planet sphere = new Planet();<br/>&#x6B64;&#x65F6;&#xFF0C;sphere&#x5177;&#x6709;&#x4E00;&#x4E2A;(&#x9ED8;&#x8BA4;)&#x503C;None&#x3002;&#x4E3A;Planet&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x6DFB;&#x52A0;&#x7684;&#x8FD9;&#x4E2A;&#x975E;&#x521D;&#x59CB;&#x5316;&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x5BF9;ObservationData&#x7ED3;&#x6784;&#x3002;&#x6700;&#x65B0;&#x521B;&#x5EFA;&#x7684;ObservationData&#x5BF9;&#x8C61;&#x7684;&#x76EE;&#x6807;&#x4E0A;&#x5177;&#x6709;None&#x548C;&#x4E00;&#x4E2A;&#x6570;&#x503C;0&#x3002;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x6E05;&#x6670;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#x8BA9;&#x7528;&#x6237;&#x4E3A;&#x4F60;&#x7684;&#x7C7B;&#x578B;&#x7684;&#x6240;&#x6709;&#x5B57;&#x6BB5;&#x660E;&#x767D;&#x7684;&#x521D;&#x59CB;&#x5316;&#xFF1A;<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;public struct ObservationData<br/>{<br/>&nbsp;&nbsp;Planet&nbsp;&nbsp; _whichPlanet; //what am I looking at?<br/>&nbsp;&nbsp;Double&nbsp;&nbsp;_magnitude; // perceived brightness.<br/>&nbsp;&nbsp;ObservationData( Planet target,<br/>&nbsp;&nbsp;&nbsp;&nbsp;Double mag )<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;_whichPlanet = target;<br/>&nbsp;&nbsp;&nbsp;&nbsp;_magnitude = mag;<br/>&nbsp;&nbsp;}<br/>}<br/>&#x4F46;&#x8BF7;&#x8BB0;&#x4F4F;&#xFF0C;&#x9ED8;&#x8BA4;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#x8FD8;&#x662F;&#x53EF;&#x8BBF;&#x95EE;&#x7684;&#xFF0C;&#x800C;&#x4E14;&#x662F;&#x7ED3;&#x6784;&#x7684;&#x90E8;&#x4EFD;&#x3002;&#x7528;&#x6237;&#x8FD8;&#x662F;&#x53EF;&#x4EE5;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7CFB;&#x7EDF;&#x521D;&#x59CB;&#x5316;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x800C;&#x4F60;&#x65E0;&#x6CD5;&#x963B;&#x6B62;&#x5B83;&#x3002;<br/>&#x5728;&#x7ED3;&#x675F;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x8F6C;&#x800C;&#x8BA8;&#x8BBA;&#x5176;&#x5B83;&#x7C7B;&#x578B;&#x4E4B;&#x524D;&#xFF0C;&#x4F60;&#x987B;&#x8981;&#x660E;&#x767D;&#x51E0;&#x4E2A;&#x7528;&#x4E8E;&#x6807;&#x8BB0;&#x7684;&#x7279;&#x6B8A;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x89C4;&#x5219;&#x3002;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x5728;&#x4F7F;&#x7528;Flags&#x7279;&#x6027;&#x65F6;&#xFF0C;&#x5FC5;&#x987B;&#x628A;None&#x7684;&#x503C;&#x8BBE;&#x7F6E;&#x4E3A;0&#xFF1A;<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;[Flags]<br/>public enum Styles<br/>{<br/>&nbsp;&nbsp;None = 0,<br/>&nbsp;&nbsp;Flat = 1,<br/>&nbsp;&nbsp;Sunken = 2,<br/>&nbsp;&nbsp;Raised = 4,<br/>}<br/>&#x5F88;&#x591A;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x4F7F;&#x7528;&#x679A;&#x4E3E;&#x6807;&#x8BB0;&#x548C;&#x4F4D;&#x8FD0;&#x7B97;&#x64CD;&#x4F5C;AND&#x8FDB;&#x884C;&#x8FD0;&#x884C;&#xFF0C;0&#x503C;&#x4F1A;&#x4E0E;&#x4F4D;&#x6807;&#x8BB0;&#x4EA7;&#x751F;&#x4E25;&#x91CD;&#x7684;&#x95EE;&#x9898;&#x3002;&#x4E0B;&#x9762;&#x8FD9;&#x4E2A;&#x5B9E;&#x9A8C;&#x5982;&#x679C;Flat&#x7684;&#x503C;&#x662F;0&#x65F6;&#xFF0C;&#x662F;&#x51B3;&#x4E0D;&#x4F1A;&#x6210;&#x529F;&#x7684;&#xFF1A;<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;if ( ( flag &amp; Styles.Flat ) != 0 ) // Never true if Flat == 0.<br/>&nbsp;&nbsp;DoFlatThings( );<br/>&#x5982;&#x679C;&#x4F60;&#x9047;&#x5230;Flags&#xFF0C;&#x786E;&#x4FDD;0&#x5BF9;&#x5B83;&#x6765;&#x8BF4;&#x662F;&#x6709;&#x6548;&#x7684;&#xFF0C;&#x5E76;&#x4E14;&#x8FD9;&#x5C31;&#x7740;&#xFF1A;&#x201C;&#x5BF9;&#x6240;&#x6709;&#x7F3A;&#x5C11;&#x7684;&#x6807;&#x8BB0;&#x3002;&#x201D;<br/>&#x53E6;&#x4E00;&#x4E2A;&#x5F88;&#x5E38;&#x89C1;&#x7684;&#x521D;&#x59CB;&#x5316;&#x95EE;&#x9898;&#x5C31;&#x662F;&#x503C;&#x7C7B;&#x578B;&#x4E2D;&#x5305;&#x542B;&#x4E86;&#x5F15;&#x7528;&#x7C7B;&#x578B;&#x3002;&#x5B57;&#x7B26;&#x4E32;&#x662F;&#x4E00;&#x4E2A;&#x5E38;&#x89C1;&#x7684;&#x4F8B;&#x5B50;&#xFF1A;<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;public struct LogMessage<br/>{<br/>&nbsp;&nbsp;private int _ErrLevel;<br/>&nbsp;&nbsp;private string _msg;<br/>}<br/>LogMessage MyMessage = new LogMessage( );<br/>MyMessage&#x5305;&#x542B;&#x4E86;&#x4E00;&#x4E2A;_msg&#x4E3A;null&#x7684;&#x5F15;&#x7528;&#x5B57;&#x6BB5;&#x3002;&#x8FD9;&#x91CC;&#x6CA1;&#x6709;&#x529E;&#x6CD5;&#x5F3A;&#x884C;&#x4F7F;&#x7528;&#x53E6;&#x4E00;&#x4E2A;&#x4E0D;&#x540C;&#x7684;&#x521D;&#x59CB;&#x5316;&#x65B9;&#x6CD5;&#xFF0C;&#x4F46;&#x4F60;&#x5229;&#x7528;&#x5C5E;&#x6027;&#x6765;&#x5C40;&#x90E8;&#x5316;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x3002;&#x4F60;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x5411;&#x6240;&#x7528;&#x7684;&#x7528;&#x6237;&#x66B4;&#x9732;_Msg&#x7684;&#x503C;&#x3002;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#xFF0C;&#x4F7F;&#x5F97;&#x5F53;&#x5B57;&#x7B26;&#x4E32;&#x4E3A;null&#x5F15;&#x7528;&#x662F;&#xFF0C;&#x7528;&#x7A7A; &#x4E32;&#x6765;&#x53D6;&#x800C;&#x4EE3;&#x4E4B;&#xFF1A;<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;public struct LogMessage<br/>{<br/>&nbsp;&nbsp;private int _ErrLevel;<br/>&nbsp;&nbsp;private string _msg;<br/>&nbsp;&nbsp;public string Message<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;get<br/>&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return (_msg != null ) ?<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_msg : string.Empty;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;set<br/>&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_msg = value;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;}<br/>}<br/>(&#x8BD1;&#x6CE8;&#xFF1A;&#x6211;&#x4E2A;&#x4EBA;&#x89C9;&#x5F97;&#x8FD9;&#x91CC;&#x8FDD;&#x53CD;&#x4E86;&#x539F;&#x5219;&#x4E00;&#x3002;&#x5F53;&#x5BF9;&#x4E24;&#x4E2A;&#x5B9E;&#x4F8B;&#x8FDB;&#x884C;&#x8D4B;&#x503C;COPY&#x65F6;&#xFF0C;&#x4F1A;&#x51FA;&#x73B0;&#xFF0C;&#x4F60;&#x660E;&#x660E;&#x4F7F;&#x7528;&#x4E86;a=b&#x7684;&#x8FD0;&#x884C;&#xFF0C;&#x4F46;&#x5B9E;&#x9645;&#x4E0A;a!=b&#x7684;&#x7ED3;&#x679C;&#x3002;&#x53EF;&#x4EE5;&#x53C2;&#x89C1;&#x539F;&#x5219;1&#x3002;)<br/>&#x5728;&#x4F60;&#x81EA;&#x5DF1;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5185;&#x90E8;&#xFF0C;&#x4F60;&#x5E94;&#x8BE5;&#x6DFB;&#x52A0;&#x8FD9;&#x6837;&#x7684;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x3002;&#x505A;&#x4E86;&#x8FD9;&#x6837;&#x7684;&#x5C40;&#x90E8;&#x5904;&#x7406;&#x540E;&#xFF0C;null&#x5F15;&#x7528;&#x5728;&#x67D0;&#x4E00;&#x4F4D;&#x7F6E;&#x505A;&#x4E86;&#x9A8C;&#x8BC1;&#x3002;&#x5F53;&#x8C03;&#x7528;&#x662F;&#x5728;&#x4F60;&#x7684;&#x7A0B;&#x5E8F;&#x96C6;&#x5185;&#x65F6;&#xFF0C;Message&#x7684;&#x8BBF;&#x95EE;&#x5668;&#x57FA;&#x672C;&#x4E0A;&#x662F;&#x53EF;&#x4EE5;&#x5F88;&#x597D;&#x7684;&#x5185;&#x8054;&#x7684;&#x3002;&#x4F60;&#x5C06;&#x4F1A;&#x53D6;&#x5F97;&#x9AD8;&#x6548;&#x4F4E;&#x9519;&#x7684;&#x4EE3;&#x7801;&#x3002;<br/>&#x7CFB;&#x7EDF;&#x4E3A;&#x6240;&#x6709;&#x7684;&#x503C;&#x7C7B;&#x578B;&#x6570;&#x636E;&#x521D;&#x59CB;&#x5316;&#x4E3A;0&#xFF0C;&#x800C;&#x6CA1;&#x6709;&#x529E;&#x6CD5;&#x9632;&#x6B62;&#x7528;&#x6237;&#x5728;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x503C;&#x7C7B;&#x578B;&#x5B9E;&#x4F8B;&#x65F6;&#xFF0C;&#x7ED9;&#x6240;&#x6709;&#x7684;&#x503C;&#x7C7B;&#x578B;&#x90FD;&#x8D4B;&#x503C;&#x4E3A;0&#x3002;&#x5982;&#x679C;&#x53EF;&#x80FD;&#xFF0C;&#x628A;0&#x8BBE;&#x7F6E;&#x4E3A;&#x81EA;&#x7136;&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#x3002;&#x7279;&#x6B8A;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4F7F;&#x7528;Flags&#x7279;&#x6027;&#x7684;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x5FC5;&#x987B;&#x786E;&#x4FDD;0&#x662F;&#x6240;&#x6709;&#x7F3A;&#x7701;&#x6807;&#x8BB0;&#x7684;&#x503C;&#x3002;<br/>========================================================<br/>The default .NET system initialization sets all objects to all 0s. There is no way for you to prevent other programmers from creating an instance of a value type that is initialized to all 0s. Make that the default value for your type.<br/>One special case is enums. Never cr&#101;ate an enum that does not include 0 as a valid choice. All enums are derived from System.ValueType. The values for the enumeration start at 0, but you can modify that behavior:<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;public enum Planet<br/>{<br/>&nbsp;&nbsp;// Explicitly assign values.<br/>&nbsp;&nbsp;// Default starts at 0 otherwise.<br/>&nbsp;&nbsp;Mercury = 1,<br/>&nbsp;&nbsp;Venus = 2,<br/>&nbsp;&nbsp;Earth = 3,<br/>&nbsp;&nbsp;Mars = 4,<br/>&nbsp;&nbsp;Jupiter = 5,<br/>&nbsp;&nbsp;Saturn = 6,<br/>&nbsp;&nbsp;Neptune = 7,<br/>&nbsp;&nbsp;Uranus = 8,<br/>&nbsp;&nbsp;Pluto = 9<br/>}<br/>Planet sphere = new Planet();<br/>sphere is 0, which is not a valid value. Any code that relies on the (normal) fact that enums are restricted to the defined set of enumerated values won&#39;t work. When you cr&#101;ate your own values for an enum, make sure that 0 is one of them. If you use bit patterns in your enum, define 0 to be the absence of all the other properties.<br/>As it stands now, you force all users to explicitly initialize the value:<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;Planet sphere = Planet.Mars;<br/>That makes it harder to build other value types that contain this type:<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;public struct ObservationData<br/>{<br/>&nbsp;&nbsp;Planet&nbsp;&nbsp; _whichPlanet; //what am I looking at?<br/>&nbsp;&nbsp;Double&nbsp;&nbsp;_magnitude; // perceived brightness.<br/>}<br/>Users who cr&#101;ate a new ObservationData object will cr&#101;ate an invalid Planet field:<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;ObservationData d = new ObservationData();<br/>The newly cr&#101;ated ObservationData has a 0 magnitude, which is reasonable. But the planet is invalid. You need to make 0 a valid state. If possible, pick the best default as the value 0. The Planet enum does not have an obvious default. It doesn&#39;t make any sense to pick some arbitrary planet whenever the user does not. When you run into that situation, use the 0 case for an uninitialized value that can be up&#100;ated later:<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;public enum Planet<br/>{<br/>&nbsp;&nbsp;None = 0,<br/>&nbsp;&nbsp;Mercury = 1,<br/>&nbsp;&nbsp;Venus = 2,<br/>&nbsp;&nbsp;Earth = 3,<br/>&nbsp;&nbsp;Mars = 4,<br/>&nbsp;&nbsp;Jupiter = 5,<br/>&nbsp;&nbsp;Saturn = 6,<br/>&nbsp;&nbsp;Neptune = 7,<br/>&nbsp;&nbsp;Uranus = 8,<br/>&nbsp;&nbsp;Pluto = 9<br/>}<br/>Planet sphere = new Planet();<br/>sphere now contains a value for None. Adding this uninitialized default to the Planet enum ripples up to the ObservationData structure. Newly cr&#101;ated ObservationData objects have a 0 magnitude and None for the target. Add an explicit constructor to let users of your type initialize all the fields explicitly:<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;public struct ObservationData<br/>{<br/>&nbsp;&nbsp;Planet&nbsp;&nbsp; _whichPlanet; //what am I looking at?<br/>&nbsp;&nbsp;Double&nbsp;&nbsp;_magnitude; // perceived brightness.<br/>&nbsp;&nbsp;ObservationData( Planet target,<br/>&nbsp;&nbsp;&nbsp;&nbsp;Double mag )<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;_whichPlanet = target;<br/>&nbsp;&nbsp;&nbsp;&nbsp;_magnitude = mag;<br/>&nbsp;&nbsp;}<br/>}<br/>But remember that the default constructor is still visible and part of the structure. Users can still cr&#101;ate the system-initialized variant, and you can&#39;t stop them.<br/>Before leaving enums to discuss other value types, you need to understand a few special rules for enums used as flags. Enums that use the Flags attribute should always set the None value to 0:<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;[Flags]<br/>public enum Styles<br/>{<br/>&nbsp;&nbsp;None = 0,<br/>&nbsp;&nbsp;Flat = 1,<br/>&nbsp;&nbsp;Sunken = 2,<br/>&nbsp;&nbsp;Raised = 4,<br/>}<br/>Many developers use flags enumerations with the bitwise AND operator. 0 values cause serious problems with bitflags. The following test will never work if Flat has the value of 0:<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;if ( ( flag &amp; Styles.Flat ) != 0 ) // Never true if Flat == 0.<br/>&nbsp;&nbsp;DoFlatThings( );<br/>If you use Flags, ensure that 0 is valid and that it means &#34;the absence of all flags.&#34;<br/>Another common initialization problem involves valuetypes that contain references. Strings are a common example:<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;public struct LogMessage<br/>{<br/>&nbsp;&nbsp;private int _ErrLevel;<br/>&nbsp;&nbsp;private string _msg;<br/>}<br/>LogMessage MyMessage = new LogMessage( );<br/>MyMessage contains a null reference in its _Msg field. There is no way to force a different initialization, but you can localize the problem using properties. You cr&#101;ated a property to export the value of _Msg to all your clients. Add logic to that property to return the empty string instead of null:<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;public struct LogMessage<br/>{<br/>&nbsp;&nbsp;private int _ErrLevel;<br/>&nbsp;&nbsp;private string _msg;<br/>&nbsp;&nbsp;public string Message<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;get<br/>&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return (_msg != null ) ?<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_msg : string.Empty;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;set<br/>&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_msg = value;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;}<br/>}<br/>You should use this property inside your own type. Doing so localizes the null reference check to one location. The Message accessor is almost certainly inlined as well, when called from inside your assembly. You&#39;ll get efficient code and minimize errors.<br/>The system initializes all instances of value typess to 0. There is no way to prevent users from creating instances of value types that are all 0s. If possible, make the all 0 case the natural default. As a special case, enums used as flags should ensure that 0 is the absence of all flags.</p><p> + <a href="#CommentCard">&#x67E5;&#x770B;&#x5F53;&#x524D;&#x65E5;&#x5FD7;&#x8BC4;&#x8BBA;</a> (0)</p><p>&nbsp;<br/><br/><a href="wap.asp?do=Login">&#x767B;&#x5F55;</a></p><p><br/>&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;</p><p><a href="wap.asp">&#x6728;&#x5B50;&#x5C4B;</a></p><p><a href="http://www.pjhome.net/wap.asp">PJBlog3&nbsp;v3.2.9.518</a>&nbsp;Inside.</p><p>Processed&nbsp;In&nbsp;0.059&nbsp;ms</p><do type="prev" label="&#x8FD4;&#x56DE;"><prev/></do></card><card id="postCommentCard"><p><b>&#x6807;&#x9898;&#x3A;</b> <a href="#MainCard">&#x45;&#x66;&#x66;&#x65;&#x63;&#x74;&#x69;&#x76;&#x65;&#x20;&#x43;&#x23;&#x20;&#x539F;&#x5219;&#x38;&#xFF1A;&#x786E;&#x4FDD;&#x30;&#x5BF9;&#x4E8E;&#x503C;&#x7C7B;&#x578B;&#x6570;&#x636E;&#x662F;&#x6709;&#x6548;&#x7684;</a></p><p><br/>你没有权限发表评论</p><p><br/>&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;</p><p><a href="wap.asp">&#x6728;&#x5B50;&#x5C4B;</a></p><p><a href="http://www.pjhome.net/wap.asp">PJBlog3&nbsp;v3.2.9.518</a>&nbsp;Inside.</p><p>Processed&nbsp;In&nbsp;0.059&nbsp;ms</p><do type="prev" label="&#x8FD4;&#x56DE;"><prev/></do></card><card id="CommentCard"><p>&#x6682;&#x65E0;&#x8BC4;&#x8BBA;</p><p><a href="#MainCard">&#x8FD4;&#x56DE;</a></p><p><br/>&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;</p><p><a href="wap.asp">&#x6728;&#x5B50;&#x5C4B;</a></p><p><a href="http://www.pjhome.net/wap.asp">PJBlog3&nbsp;v3.2.9.518</a>&nbsp;Inside.</p><p>Processed&nbsp;In&nbsp;0.059&nbsp;ms</p><do type="prev" label="&#x8FD4;&#x56DE;"><prev/></do></card>
</wml>
