string str1="abc";
string str2=str1;
Console.WriteLine(str1);
Console.WriteLine(str2);
str2="cba";
Console.WriteLine(str1);
Console.WriteLine(str2);System.String继承于System.Object,使用赋值运算符时,.net framework到底做了什么?求解释.

解决方案 »

  1.   

    System.String中用于保存字符串的字段是什么类型,存储在什么地方?求System.String的完整源码。
      

  2.   

    string 重载了运算符,两个字符串相加会重新分配内存空间。
      

  3.   

    String 对象是 System.Char 对象的有序集合,用于表示字符串。
    看看MSDNhttp://msdn.microsoft.com/zh-cn/library/system.string(v=VS.80).aspx
      

  4.   


    // ==++== 
    //
    //   Copyright (c) Microsoft Corporation.  All rights reserved.
    //
    // ==--== 
    /*============================================================
    ** 
    ** Class:  String 
    **
    ** 
    ** Purpose: Contains headers for the String class.  Actual implementations
    ** are in String.cpp
    **
    ** 
    ===========================================================*/
    namespace System { 
        using System.Text; 
        using System;
        using System.Runtime.ConstrainedExecution; 
        using System.Globalization;
        using System.Threading;
        using System.Collections;
        using System.Collections.Generic; 
        using System.Runtime.CompilerServices;
        using Microsoft.Win32; 
        using System.Runtime.InteropServices; 
        using va_list = System.ArgIterator;
        // 
        // For Information on these methods, please see COMString.cpp
        //
        // The String class represents a static string of characters.  Many of
        // the String methods perform some type of transformation on the current 
        // instance and return the result as a new String. All comparison methods are
        // implemented as a part of String.  As with arrays, character positions 
        // (indices) are zero-based. 
        //
        // When passign a null string into a constructor in VJ and VC, the null should be 
        // explicitly type cast to a String.
        // For Example:
        // String s = new String((String)null);
        // Text.Out.WriteLine(s); 
        //
    [System.Runtime.InteropServices.ComVisible(true)] 
        [Serializable] public sealed class String : IComparable, ICloneable, IConvertible, IEnumerable 
    #if GENERICS_WORK
            , IComparable<String>, IEnumerable<char>, IEquatable<String> 
    #endif
        {        // 
            //
     
     
            [NonSerialized]private int  m_arrayLength;
            [NonSerialized]private int  m_stringLength; 
            [NonSerialized]private char m_firstChar;        //private static readonly char FmtMsgMarkerChar='%';
            //private static readonly char FmtMsgFmtCodeChar='!'; 
            //These are defined in Com99/src/vm/COMStringCommon.h and must be kept in sync.
            private const int TrimHead = 0; 
            private const int TrimTail = 1; 
            private const int TrimBoth = 2;
     
            // The Empty constant holds the empty string value.
            //We need to call the String constructor so that the compiler doesn't  this as a literal.
            //Marking this as a literal would mean that it doesn't show up as a field which we can access
            //from native. 
            public static readonly String Empty = "";
     
     ...
    }// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
    // Copyright (c) Microsoft Corporation. All rights reserved.
      

  5.   

    string + 运算会从新分配内存