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)
{ ......
SWF之间通信、Flex与SWF之间通信、C#与SWF之间通信
一、SWF之间通信(各SWF文件均没有包含关系——非内部嵌入加载,均独立)
使用 LocalConnection 类可以创建一个 LocalConnection 对象,该对象可在一个 SWF 文件中或多个 SWF 文件间,调用另一个 LocalConnection 对象中的方法。 通过本地连接,可以在 SWF ......
原先一直用BinaryFormatter来序列化挺好,可是最近发现在WinCE下是没有办法进行BinaryFormatter操作,很不爽,只能改成了BinaryWriter和BinaryReader来读写,突然想到能不能用XML来序列化?于是在网上查了些资料便写了些实践性代码,做些记录,避免以后忘记。
序列化对象
public class People
......
1)Xml文档示例(xmlsample.xml):
Code
<?xml version="1.0" encoding="iso-8859-1" ?>
<music>
<song title="Oh,girl">
<artist>The Chi-lites</artist>
<genre>Soul</genre>
&nb ......