string类型本身是按值来操作,但是加上(object)后就转为引用类型的了

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArraysType
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 基本类型的最大值和最小值
            byte bMax = byte.MaxValue;
            byte bMin = byte.MinValue;

            Console.WriteLine(bMax);
            Console.WriteLine(bMin);

            short sMax = short.MaxValue;
            short sMin = short.MinValue;

            Console.WriteLine(sMax);
            Console.WriteLine(sMin);

            int iMax = int.MaxValue;
            int iMin = int.MinValue;

            Console.WriteLine(iMax);
            Console.WriteLine(iMin);

            char cMax = char.MaxValue;
            char c = '赵';
            Console.WriteLine(c);


            Console.WriteLine(cMax);
            
            #endregion

            #region string类型的练习
            string str1 = "中国人";
            string str2 = "中国人";
            if (str1 == str2)
            {
                Console.WriteLine("\n这两个相等");
            }

            if ((object)str1 == (object)str2)
            {
                Console.WriteLine("他们的object对象相等");
            }

            if (str1.Equals(str2))
            {
                Console.WriteLine("是同一个变量");
            }


            string str3 = str1;
            str3 = "新中国人";

            Console.WriteLine("\nstr1:{0},\nstr3:{1}\n",str1,str3);

            string str4 = "中";
            str4 = str4+"国人";
            if (str1 == str4)
            {
                Console.WriteLine("这两个相等");
            }

            if ((object)str1 == (object)str4)
            {
                Console.WriteLine("他们的object对象相等");
            }

            if (((object)str1).Equals((object)str4))
            {
                Console.WriteLine("是同一个变量");
            }


            #endregion

            char cc = 'c';
            char a = 'a';
            Console.WriteLine("{0},{1}",cc,a);
            Console.ReadLine();

        }
    }
}





==,(object),equals这三者之间的区别在这个程序中有了初步的判断,对于按值和按引用类型的操作有的真实的程序来比较。记住默认的和加范围之后的区别,这是关键所在。
string类型历来是比较特殊的!

你可能感兴趣的:(string类型本身是按值来操作,但是加上(object)后就转为引用类型的了)