C#中string作为引用类型与类的区别的一个问题
RT。先贴代码
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Value_Ref_test1
{
class Program
{
static void Main(string[] args)
{
point a = new point (10,10) ;
point b = a;
a.x = 20;
Console.WriteLine(a.x);
Console.WriteLine(b.x);
}
}
public class point
{
public int x;
public int y;
public point(int Xvalue,int Yvalue)
{
this.x = Xvalue;
this.y = Yvalue;
}
}
}
这样的话最后会输出
20
20
因为a,b两个变量引向了同一个堆内存上的对象。
但是同样string也是引用类型。
C# code
string a ="123";
string b = a;
b = "321";
再输出的话就是b,a就是321,123。
考虑可能是由于string在编译时被内置,于是又试了一下非内置的string(感觉这样写string不会被内置。)
C# code
Random a = new Random();
string b = a.Next().ToString();
string c = b;
Console.WriteLine("b={0}",b);
Console.WriteLine("c={0}", c);
c = a.Next().ToString();
Console.WriteLine("b={0}", b);
Console.WriteLine("c={0}", c);
OK,最后结果b,c还是输出的不同结果。。。
等待懂得人解答为什么。。。
相关文档:
// 按模版比例生成缩略图(以流的方式获取源文件)
//生成缩略图函数
//顺序参数:源图文件流、缩略图存放地址、模版宽、模版高
//注:缩略图大小控制在模版区域内
public static void MakeSmallImg(System.IO.Stream fromFileStream,string fileSaveUrl,System.Double templateWidth,System.Double templateHeight)
{ ......
<Language from="SQL" To="C#">
<Type from="bigint" To="long" />
<Type from="binary" To="object" />
<Type from="bit" To="bool" />
<Type from="char" To="string" />
<Type from="datetime" To="DateTime" ......
编译:C程序直接编译成标准的二进制可执行的代码,但C#的源程序并不是被编译成二进制可执行的形式,而是一种中间语言(MSIL),类似JAVA中的字节码
结构体:C#的结构体与C++的结构体相似。但是C#的结构体与类是不同的,而且不支持继承。
预编译:C#中存在预编译的指令支持条件编译,警告,错误报告和编译行控制。其指令 ......
public class yzzSerialize
{
private yzzSerialize()
{ }
private static yzzCache cache = new yzzCache();
public static T GetfromXml<T>(string xmlpath, T t)
{
using (FileStream fs = new FileStream(xmlpath, FileMode.Open, FileAcces ......