string是一种特殊的引用类型,当给其赋值时会初始化一个新的string,即new String();
2013-02-18 14:35
323 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TEST
{
class Program
{
static void Main(string[] args)
{
//Obj obj = new Obj();
//Obj obj2 = obj;
//obj.Value = "1";
//obj.ID = 1;
//Console.WriteLine("obj.value:"+obj.Value +" ID:"+obj.ID);
//Console.WriteLine("obj2.value:" + obj2.Value + " ID:" + obj2.ID);
//obj.Value = "11";
//obj.ID = 22;
//Console.WriteLine("obj.value:" + obj.Value + " ID:" + obj.ID);
//Console.WriteLine("obj2.value:" + obj2.Value + " ID:" + obj2.ID);
//obj2.Value = "111";
//obj2.ID = 222;
//Console.WriteLine("obj.value:" + obj.Value + " ID:" + obj.ID);
//Console.WriteLine("obj2.value:" + obj2.Value + " ID:" + obj2.ID);
string str1;
string str2;//string是一种特殊的引用类型,当给其赋值时会初始化一个新的string,即new String();
str1 = "string1";
str2 = str1;
Console.WriteLine("str1:" + str1);
Console.WriteLine("str2:" + str2);
str2 = "string2";
Console.WriteLine("str1:" + str1);
Console.WriteLine("str2:" + str2);
Console.Read();
}
}
class Obj
{
public string Value;
public int ID;
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TEST
{
class Program
{
static void Main(string[] args)
{
//Obj obj = new Obj();
//Obj obj2 = obj;
//obj.Value = "1";
//obj.ID = 1;
//Console.WriteLine("obj.value:"+obj.Value +" ID:"+obj.ID);
//Console.WriteLine("obj2.value:" + obj2.Value + " ID:" + obj2.ID);
//obj.Value = "11";
//obj.ID = 22;
//Console.WriteLine("obj.value:" + obj.Value + " ID:" + obj.ID);
//Console.WriteLine("obj2.value:" + obj2.Value + " ID:" + obj2.ID);
//obj2.Value = "111";
//obj2.ID = 222;
//Console.WriteLine("obj.value:" + obj.Value + " ID:" + obj.ID);
//Console.WriteLine("obj2.value:" + obj2.Value + " ID:" + obj2.ID);
string str1;
string str2;//string是一种特殊的引用类型,当给其赋值时会初始化一个新的string,即new String();
str1 = "string1";
str2 = str1;
Console.WriteLine("str1:" + str1);
Console.WriteLine("str2:" + str2);
str2 = "string2";
Console.WriteLine("str1:" + str1);
Console.WriteLine("str2:" + str2);
Console.Read();
}
}
class Obj
{
public string Value;
public int ID;
}
}
相关文章推荐
- 1.在使用new创建数组后,此时数组还是一个引用数组。 只有再创建新的对象,并把对象赋值给数组引用,到此初始化结束2.什么是引用类型?
- 理解C# String类型:特殊的引用类型
- C++中有string类,string是一个类不是一种类型,c语言中没有
- 黑马程序员-引用类型传递参数的特殊情况(string)
- 6-2-1 字符串-字符串变量String-创建字符串变量-初始化字符串变量-字符串连接-输入字符串(单词、行)-对象变量的赋值-比较两个字符串是否同一个-比较两个字符串内容是否相同
- JavaSE8基础 String是特殊的引用类型,在函数的参数传递中只能把它当做 值类型来看待
- 05引用类型以及特殊引用类型string
- 不能将类型为‘std::string&’的非 const 引用初始化为类型为‘const char*’的临时变量
- C# string 拥有值类型特点的特殊引用类型 “字符串具有恒等性”
- 【转载】:C# string 特殊的引用类型
- 一个例子说明java数据类型包括对象是赋值还是引用!!!
- java中“==”和equals方法的区别,再加上特殊的String引用类型
- string是特殊的引用类型,特殊在何处??
- 值类型与引用类型(特殊的string) Typeof和GetType() 静态和非静态使用 参数传递 相关知识
- [No0000B4].Net中String是引用类型还是值类型,答string是特殊的引用类型
- C++中string类型的初始化与赋值
- String类型是特殊的引用类型
- 引用类型传递参数的特殊情况(string)
- String属于“假引用类型”,代码为证(一个String引发的血案...)
- (集合和引用类型、基本数据类型赋值不一样)一个简单的java问题 先后的赋值问题