English 中文(简体)
返回
原标题:return new string vs .ToString()

采用以下法典:

    public static string ReverseIt(string myString)
    {
        char[] foo = myString.ToCharArray();
        Array.Reverse(foo);
        return new string(foo);
    }

我的理解是,扼杀是不可调和的,但我所理解的是,为什么需要称作新的扼杀。

return new string(foo);

而不是

return foo.ToString();

我必须假定,它与重新评估沙阿雷(但只是一个gues)。

两者之间有何区别,以及你知道何时返回新的扼杀而不是返回制度。 这代表了目前的目标?

最佳回答

很简单,因为把ToString(电话)放在一个果园里给你。

System.Char[]

提 出

    char[] ca = "Hello world".ToCharArray();
    Console.WriteLine("{0}", ca);

页: 1 Hello World

http://www.ohchr.org。 反倒转播是一种坏想法,。 Tony and Jon提到了这一点——现在著名的是 - 发言次数:

问题回答

第二项呼吁是就果园阵列案例开展统计工作,而第一项则利用护卫建筑从果园获得座标。 他们彼此之间确实没有任何关系。

The IL for the 2 function:

private string test(String myString){

        char[] foo = myString.ToCharArray(); 
        Array.Reverse(foo); 
        return new string(foo); 
}


test:
IL_0000:  nop         
IL_0001:  ldarg.1     
IL_0002:  callvirt    System.String.ToCharArray
IL_0007:  stloc.0     
IL_0008:  ldloc.0     
IL_0009:  call        System.Array.Reverse
IL_000E:  nop         
IL_000F:  ldloc.0     
IL_0010:  newobj      System.String..ctor
IL_0015:  stloc.1     
IL_0016:  br.s        IL_0018
IL_0018:  ldloc.1     
IL_0019:  ret         


private string tess(String myString)
{

        char[] foo = myString.ToCharArray(); 
        Array.Reverse(foo); 
        return foo.ToString(); 
}

tess:
IL_0000:  nop         
IL_0001:  ldarg.1     
IL_0002:  callvirt    System.String.ToCharArray
IL_0007:  stloc.0     
IL_0008:  ldloc.0     
IL_0009:  call        System.Array.Reverse
IL_000E:  nop         
IL_000F:  ldloc.0     
IL_0010:  callvirt    System.Object.ToString
IL_0015:  stloc.1     
IL_0016:  br.s        IL_0018
IL_0018:  ldloc.1     
IL_0019:  ret         

形形形色色色的外向航天中心发出快速/优化的外部呼吁,因此在这种情况下它能够更快地运作。

<代码>String有一个专门的构造:

[MethodImpl(MethodImplOptions.InternalCall)]
public extern String(char[] value);




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签