zoukankan      html  css  js  c++  java
  • .net(关于字符串的相等问题[比较重要])

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace TestString
    {
        class Program
        {
            static void Main(string[] args)
            {
                string a = "hello";
                string b = "h";
                b +="ello";
                string c = "hello";
    
                if ((object)a == (object)b)
                {
                    Console.WriteLine("True");
                }
                else
                {
                    Console.WriteLine("False");
                }
    
                if ((object)a == (object)c)
                {
                    Console.WriteLine("True");
                }
                else
                {
                    Console.WriteLine("False");
                }
            
            }
        }
    }
    注,这属于.net内存对字符串的分配问题,如果是没有经过相加的字符串,如果内容相同地址也相同,即为同一区域。如果是组装以后才相等的,则重新分配内存!
  • 相关阅读:
    while练习题
    流程控制之for循环
    流程控制之while循环
    流程控制之if判断
    作业
    基本运算符
    输入输出
    基本数据类型
    变量part2
    JDBC中创建表
  • 原文地址:https://www.cnblogs.com/wjchang/p/3671597.html
Copyright © 2011-2022 走看看