In porting a .net framework app to .net core app, there are some uses of String.Copy
to copy strings. But it looks this method is removed from .net core, so how would you copy a string in .net core app, and as a result, it is not present in uwp too. Does assignment string b = a;
in .net core means something different as in .netframework?
The copy is used in this code:
public DataDictionary(DataDictionary src)
:this()
{
this.Messages = src.Messages;
this.FieldsByName = src.FieldsByName;
this.FieldsByTag = src.FieldsByTag;
if (null != src.MajorVersion)
this.MajorVersion = string.Copy(src.MajorVersion);
if (null != src.MinorVersion)
this.MinorVersion = string.Copy(src.MinorVersion);
if (null != src.Version)
this.Version = string.Copy(src.Version);
}
Copy(String) Method is used to create a new instance of String with the same value as a specified String. In other words, this method is used to copy the data of one string into a new string.
strcpy(): Using the inbuilt function strcpy() from string. h header file to copy one string to the other. strcpy() accepts a pointer to the destination array and source array as a parameter and after copying it returns a pointer to the destination string.
In C#, Copy() is a string method. It is used to create a new instance of String with the same value for a specified String. The Copy() method returns a String object, which is the same as the original string but represents a different object reference.
In C#, Clone() is a String method. It is used to clone the string object, which returns another copy of that data. In other words, it returns a reference to this instance of String. The return value will be only another view of the same data.
This is not as elegant as string.Copy()
, but if you do not want reference equality for whatever reason, consider using:
string copiedString = new string(stringToCopy);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With