zoukankan      html  css  js  c++  java
  • 何时readonly 字段不是 readonly 的?结果出呼你想象!!! 不及格的程序员

    作者:不及格的程序员-八神

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

    运行一下下面的代码你就无语了,介绍了两种方式,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 

    南来地,北往的,上班的,下岗的,走过路过不要错过!

    ======================个性签名=====================

    之前认为Apple 的iOS 设计的要比 Android 稳定,我错了吗?

    下载的许多客户端程序/游戏程序,经常会Crash,是程序写的不好(内存泄漏?刚启动也会吗?)还是iOS本身的不稳定!!!

    如果在Android手机中可以简单联接到ddms,就可以查看系统log,很容易看到程序为什么出错,在iPhone中如何得知呢?试试Organizer吧,分析一下Device logs,也许有用.

    我的开发工具

    对于博客园里的网友,不敢称为叫"程序员"的人,你们攻击性太强,看来你们是不会想到我的用意的.园子里有不少人都非常喜欢Jeffrey,是因为它的第一版 框架设计 CLR via C#.
    可是从第一版到现在的第三版,没有看到真正底层的东西,内容仅仅是比MSDN文档更丰富一些,可能是我的要求太高了吧.
    也就是因为它很多时候会接触到微软开发人员,会经常聊聊某些问题而已,而它又将这些问题反应到书中.也许它就像一个小记者.
    它的年龄大我们不多,我的孩子与它小儿子一般大,如果我能向它那样出入微软与它们开发人员长时间交流,不仅仅会牛成它这样.....
    可是微软的开发人员不会扔太多时间在它这儿的.所以它会整天追着这个,赶它那个..屁颠个不停吧...
    而它的另一版被称为好书的 Windows核心编程,更是没有什么深度可言,仅仅是将windows提供的api,以及内核功能再重申了一遍.
    这些书对晋及编程知识是有些贡献的,再说一遍我不是在匾低谁,说说想法而已.

  • 相关阅读:
    EventBus详解
    Java BigDecimal使用
    StringFormate使用
    Sourcetree拉取推送问题
    Android下拉刷新控件android-Ultra-Pull-To-Refresh 使用
    SourceTree跳过Atlassian账号,免登陆,跳过初始设置
    Android Studio3.2新建项目gradle read time out
    底部导航栏使用BottomNavigationBar
    PopupWindow封装
    电脑连接真机,但是androidstudio不显示手机,ADB Interface黄色感叹号
  • 原文地址:https://www.cnblogs.com/ioriwellings/p/1770084.html
Copyright © 2011-2022 走看看