[Tips]:值类型和引用类型的一个例子

简介:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using  System;
using  System.Collections.Generic;
using  System.Linq;
using  System.Text;
 
namespace  ConsoleApplication1
{
     class  Program
     {
         static  void  Main( string [] args)
         {
             string [] a = { "a" , "b" , "c" , "d"  };
             var  b = a.SingleOrDefault(c => c.Equals( "b" ));
             b = "hello world" ;
             if  (a[1] == "hello world" )
             {
                 Console.Out.WriteLine( "true" );
             }
             else
             {
                 Console.Out.WriteLine( "false" );
             }
             Console.ReadLine();
             List<Person> allPersons = new  List<Person>{
                 new  Person{ Name= "Jack" },
                 new  Person{ Name= "Crystal" }
             };
             Person p= new  Person();
             p = allPersons.SingleOrDefault(c => c.Name == "Crystal" );
             p.Name = "Tom" ;
             foreach  ( var  item in  allPersons)
             {
                 Console.Out.WriteLine(item.Name);               
             }
             Console.ReadLine();
        }
     }
     public  class  Person
     {
         public  string  Name { get ; set ; }
     }
}
结果:
 

image

本文转自敏捷的水博客园博客,原文链接http://www.cnblogs.com/cnblogsfans/archive/2009/07/22/1528663.html如需转载请自行联系原作者


王德水

相关文章
|
Android开发 Shell
Android模拟点击的四种方式
导论 在Android中模拟一个点击事件有三种方式是通过模拟MotionEvent来实现;一种是通过ADB来实现;一种是通过Instrumentation测试框架来实现 第一种:模拟MotionEvent 通用方法如下: private void setSimulateClick(View ...
9017 0
|
存储 监控 关系型数据库
GTS解密--GTS的原理、架构与特点
全局事务服务(Global Transaction Service,简称 GTS)是阿里新推出的分布式事务处理方案,对其深入分析的资料相对匮乏。本文的目标是剖析GTS的技术路线,厘清其优势与约束。
23087 0
|
数据安全/隐私保护 Windows C语言