XSLT存档  

不及格的程序员-八神

 查看分类:  ASP.NET XML/XSLT JavaScripT   我的MSN空间Blog
作者:不及格的程序员-八神

  不要以为只有在构造函数中它们是可以更改的,其实还有其它的状况。

运行一下下面的代码你就无语了,介绍了两种方式,out输出与联合体。


 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.UI;
 6 using System.Web.UI.WebControls;
 7 using System.Runtime.InteropServices;
 8 
 9 namespace Hello_2010
10 {
11     public partial class _Default : System.Web.UI.Page
12     {
13         protected void Page_Load(object sender, EventArgs e)
14         {
15             S3 s3 = new S3();
16             int x = s3.A.X;
17             s3.B.X++; //A.X已经变成1了,不信你看看。。。。
18 
19             S s = new S(42);
20             s.MultiplyInto(10out s); //变量X变成420了,而不是42。
21 
22             
23         }
24 
25         protected void Button1_Click(object sender, EventArgs e)
26         {
27             //this.Label1.Text = "ok";
28             //this.Label1.Text += this.FileUpload1.FileName;
29         }
30     }
31 
32     struct S 
33     {
34         public readonly int X;
35 
36         public S(int x) { X = x; }
37 
38         public void MultiplyInto(int c, out S target) 
39         {
40             System.Console.WriteLine(this.X);
41             target = new S(X * c);
42             System.Console.WriteLine(this.X); // same? it is, after all, readonly.
43         }
44     }
45 
46 
47     struct S1
48     {
49         public readonly int X;
50     }
51 
52     struct S2
53     {
54         public int X;
55     }
56 
57     [StructLayout(LayoutKind.Explicit)]
58     struct S3
59     {
60         [FieldOffset(0)]
61         public S1 A;
62         [FieldOffset(0)]
63         public S2 B;
64     }
65 

 

 

posted on 2010-07-02 16:43  不及格的程序员-八神  阅读(2931)  评论(43编辑  收藏  举报