extends System.Object
extends System.IComparable
extends System.ICloneable
extends System.Collections.IEnumerable
| Variables: |
|---|
public System.Char Chars |
public System.Int32 Length |
| Constructors: |
|---|
public System.String(System.Char c, System.Int32 count) Constructs and initializes a new instance of System.String . Parameter c: A System.Char . Parameter count: A System.Int32 containing the number of occurrences of c. Throws: : count is less than zero. If the specified number is 0, System.String.Empty is created. Example: The following example demonstrates using this constructor. using System;
public class StringExample {
public static void Main() {
string s = new String('a', 10);
Console.WriteLine(s);
}
}
The output is aaaaaaaaaa |
public System.String(System.Char* value) Constructs and initializes a new instance of System.String using a specified pointer to a sequence of Unicode characters. Parameter value: A pointer to a null-terminated array of Unicode characters. If value is a null pointer, System.String.Empty is created. This member is not CLS-compliant. For a CLS-compliant alternative, use the System.String(System.Char ) constructor. This constructor copies the sequence of Unicode characters at the specified pointer until a null character (hexadecimal 0x00) is reached. If the specified array is not null-terminated, the behavior of this constructor is system dependent. For example, such a situation might cause an access violation. In C# this constructor is defined only in the context of unmanaged code. |
public System.String(System.Char[] value) Constructs and initializes a new instance of System.String by copying the specified array of Unicode characters. Parameter value: An array of Unicode characters. If the specified array is a null reference or contains no elements, System.String.Empty is created. |
public System.String(System.Char* value, System.Int32 startIndex, System.Int32 length) Constructs and initializes a new instance of System.String using a specified pointer to a sequence of Unicode characters, the index within that sequence at which to start copying characters, and the number of characters to be copied to construct the System.String . Parameter value: A pointer to an array of Unicode characters. Parameter startIndex: A System.Int32 containing the index within the array referenced by value from which to start copying. Parameter length: A System.Int32 containing the number of characters to copy from value to the new System.String. If length is zero, System.String.Empty is created. Throws: : startIndex or length is less than zero. -or- value is a null pointer and length is not zero. This member is not CLS-compliant. For a CLS-compliant alternative, use the System.String(System.Char, System.Int32, System.Int32) constructor. This constructor copies Unicode characters from value, starting at startIndex and ending at (startIndex + length - 1). If the specified range is outside of the memory allocated for the sequence of characters, the behavior of this constructor is system dependent. For example, such a situation might cause an access violation. In C# this constructor is defined only in the context of unmanaged code. |
public System.String(System.SByte* value, System.Int32 startIndex, System.Int32 length, System.Text.Encoding enc) Constructs and initializes a new instance of the String class to the value indicated by a specified pointer to an array of 8-bit signed integers, a starting character position within that array, a length, and an Encoding object. Parameter value: A pointer to a System.SByte array. Parameter startIndex: A System.Int32 containing the starting position within value. Parameter length: A System.Int32 containing the number of characters within value to use. If length is zero, System.String.Empty is created. Parameter enc: A System.Text.Encoding object that specifies how the array referenced by value is encoded. Throws: : startIndex or length is less than zero. -or- value is a null pointer and length is not zero. If value is a null pointer, a System.String.Empty instance is constructed. |
public System.String(System.Char[] value, System.Int32 startIndex, System.Int32 length) Constructs and initializes a new instance of System.String using an array of Unicode characters, the index within array at which to start copying characters, and the number of characters to be copied. Parameter value: An array of Unicode characters. Parameter startIndex: A System.Int32 containing the index within the array referenced by value from which to start copying. Parameter length: A System.Int32 containing the number of characters to copy from the value array. If length is zero, System.String.Empty is created. Throws: : value is a null reference. Throws: : startIndex or length is less than zero. -or- The sum of startIndex and length is greater than the number of elements in value . This constructor copies the sequence Unicode characters found at value between indexes startIndex and startIndex + length - 1. |
| Functions: |
|---|
public System.Object Clone() Returns a reference to the current instance of System.String. Returns: A reference to the current instance of System.String. System.String.Clone does not generate a new System.String instance. Use the System.String.Copy(System.String) or System.String.CopyTo(System.Int32,System.Char[],System.Int32,System.Int32) method to create a separate System.String object with the same value as the current instance. This method is implemented to support the System.ICloneable interface. |
public static System.Int32 Compare(System.String strA, System.Int32 indexA, System.String strB, System.Int32 indexB, System.Int32 length, System.Boolean ignoreCase) Compares substrings of two strings. Parameter strA: The first System.String containing a substring to compare. Parameter indexA: A System.Int32 containing the starting index of the substring within strA. Parameter strB: The second System.String containing a substring to compare. Parameter indexB: A System.Int32 containing the starting index of the substring within strB. Parameter length: A System.Int32 containing the number of characters in the substrings to compare. If length is zero, then zero is returned. Parameter ignoreCase: A System.Boolean indicating if the comparison is case-insensitive. If ignoreCase is true, the comparison is case-insensitive. If ignoreCase is false, the comparison is case-sensitive, and upper case letters evaluate greater than their lower case equivalents. Returns: A System.Int32 containing a value that reflects the sort order of substrings of the two specified strings. The following table defines the conditions under which the returned value is a negative number, zero, or a positive number. Throws: : The sum of indexA and length is greater than strA .Length -or- The sum of indexB and length is greater than strB .Length -or- indexA, indexB, or length is negative. -or- strA is null and indexA is non-zero. -or- strB is null and indexB is non-zero. When either of the String arguments is the null reference an System.ArgumentOutOfRangeException shall be thrown if the corresponding index is non-zero. The result of comparing any System.String (including the empty string) to a null reference is greater than zero. The result of comparing two null references is zero. Upper case letters evaluate greater than their lower case equivalents. The method uses the culture of the current thread to determine the ordering of individual characters. The two strings are compared on a character-by-character basis. Example: The following example demonstrates comparing substrings with and without case sensitivity. using System;
public class StringCompareExample {
public static void Main() {
string strA = "STRING A";
string strB = "string b";
int first = String.Compare( strA, strB, true );
int second = String.Compare( strA, 0, strB, 0, 4, true );
int third = String.Compare( strA, 0, strB, 0, 4, false );
Console.WriteLine( "When the string 'STRING A' is compared to the string 'string b' in a case-insensitive manner, the return value is {0}.", first );
Console.WriteLine( "When the substring 'STRI' of 'STRING A' is compared to the substring 'stri' of 'string b' in a case-insensitive manner, the return value is {0}.", second );
Console.WriteLine( "When the substring 'STRI' of 'STRING A' is compared to the substring 'stri' of 'string b' in a case-sensitive manner, the return value is {0}.", third );
}
}
The output is When the string 'STRING A' is compared to the string 'string b' in a case-insensitive manner, the return value is -1. When the substring 'STRI' of 'STRING A' is compared to the substring 'stri' of 'string b' in a case-insensitive manner, the return value is 0. When the substring 'STRI' of 'STRING A' is compared to the substring 'stri' of 'string b' in a case-sensitive manner, the return value is 1. |
public static System.Int32 Compare(System.String strA, System.Int32 indexA, System.String strB, System.Int32 indexB, System.Int32 length) Compares substrings of two strings. Parameter strA: The first System.String to compare. Parameter indexA: A System.Int32 containing the starting index of the substring within strA. Parameter strB: The second System.String to compare. Parameter indexB: A System.Int32 containing the starting index of the substring within strB. Parameter length: A System.Int32 containing the number of characters in the substrings to compare. If length is zero, then zero is returned. Returns: A System.Int32 containing a value that reflects the sort order of substrings of the two specified strings. The following table defines the conditions under which the returned value is a negative number, zero, or a positive number. Throws: : The sum of indexA and length is greater than strA .Length . -or- The sum of indexB and length is greater than strB .Length . -or- indexA, indexB, or length is negative. -or- strA is null and indexA is non-zero. -or- strB is null and indexB is non-zero. When either of the String arguments is the null reference an System.ArgumentOutOfRangeException shall be thrown if the corresponding index is non-zero. The result of comparing any System.String (including the empty string) to a null reference is greater than zero. The result of comparing two null references is zero. Upper case letters evaluate greater than their lower case equivalents. The method uses the culture of the current thread to determine the ordering of individual characters. The two strings are compared on a character-by-character basis. Example: The following example demonstrates comparing substrings. using System;
public class StringCompareExample {
public static void Main() {
string strA = "A string";
string strB = "B ring";
int first = String.Compare( strA, 4, strB, 2, 3 );
int second = String.Compare( strA, 3, strB, 3, 3 );
Console.WriteLine( "When the substring 'rin' of 'A string' is compared to the substring 'rin' of 'B ring', the return value is {0}.", first );
Console.WriteLine( "When the substring 'tri' of 'A string' is compared to the substring 'ing' of 'B ring', the return value is {0}.", second );
}
}
The output is When the substring 'rin' of 'A string' is compared to the substring 'rin' of 'B ring', the return value is 0. When the substring 'tri' of 'A string' is compared to the substring 'ing' of 'B ring', the return value is 1. |
public static System.Int32 Compare(System.String strA, System.String strB, System.Boolean ignoreCase) Returns sort order of two System.String objects. Parameter strA: The first System.String to compare. Can be a null reference. Parameter strB: The second System.String to compare. Can be a null reference. Parameter ignoreCase: A System.Boolean indicating whether the comparison is case-insensitive. If ignoreCase is true, the comparison is case-insensitive. If ignoreCase is false, the comparison is case-sensitive, and upper case letters evaluate greater than their lower case equivalents. Returns: A System.Int32 containing a value that reflects the sort order of the two specified strings. The following table defines the conditions under which the returned value is a negative number, zero, or a positive number. The result of comparing any System.String (including the empty string) to a null reference is greater than zero. The result of comparing two null references is zero. Upper case letters evaluate greater than their lower case equivalents. The method uses the culture of the current thread to determine the ordering of individual characters. The two strings are compared on a character-by-character basis. String.Compare(strA, strB, false) is equivalent to String.Compare(strA, strB ). Example: The following example demonstrates comparing strings with and without case sensitivity. using System;
public class StringCompareExample {
public static void Main() {
string strA = "A STRING";
string strB = "a string";
int first = String.Compare( strA, strB, true );
int second = String.Compare( strA, strB, false );
Console.WriteLine( "When 'A STRING' is compared to 'a string' in a case-insensitive manner, the return value is {0}.", first );
Console.WriteLine( "When 'A STRING' is compared to 'a string' in a case-sensitive manner, the return value is {0}.", second );
}
}
The output is When 'A STRING' is compared to 'a string' in a case-insensitive manner, the return value is 0. When 'A STRING' is compared to 'a string' in a case-sensitive manner, the return value is 1. |
public static System.Int32 Compare(System.String strA, System.String strB) Compares two System.String objects in a case sensitive manner. Parameter strA: The first System.String to compare. Can be a null reference. Parameter strB: The second System.String to compare. Can be a null reference. Returns: A System.Int32 containing a value that reflects the sort order of the two specified strings. The following table defines conditions under which the returned value is a negative number, zero, or a positive number. This method performs a case-sensitive operation. The result of comparing any System.String (including the empty string) to a null reference is greater than zero. The result of comparing two null references is zero. Upper case letters evaluate greater than their lower case equivalents. The method uses the culture of the current thread to determine the ordering of individual characters. The two strings are compared on a character-by-character basis. |
public static System.Int32 CompareOrdinal(System.String strA, System.String strB) Compares two specified System.String objects based on the code points of the contained Unicode characters. Parameter strA: The first System.String to compare. Parameter strB: The second System.String to compare. Returns: A System.Int32 containing a value that reflects the sort order of the two specified strings. The following table defines the conditions under which the returned value is a negative number, zero, or a positive number. The result of comparing any System.String (including the empty string) to a null reference is greater than zero. The result of comparing two null references is zero. Upper case letters evaluate greater than their lower case equivalents. The method uses the culture of the current thread to determine the ordering of individual characters. The two strings are compared on a character-by-character basis. |
public static System.Int32 CompareOrdinal(System.String strA, System.Int32 indexA, System.String strB, System.Int32 indexB, System.Int32 length) Compares substrings of two specified System.String objects based on the code points of the contained Unicode characters. Parameter strA: The first System.String to compare. Parameter indexA: A System.Int32 containing the starting index of the substring in strA. Parameter strB: The second System.String to compare. Parameter indexB: A System.Int32 containing the starting index of the substring in strB. Parameter length: A System.Int32 containing the number of characters in the substrings to compare. Returns: A System.Int32 containing a value that reflects the sort order of the two specified strings. The following table defines the conditions under which the returned value is a negative number, zero, or a positive number. Throws: : The sum of indexA and length is greater than strA .Length -or- The sum of indexB and length is greater than strB .Length -or- indexA, indexB, or lengthis negative. -or- strA is null and indexA is non-zero. -or- strB is null and indexB is non-zero. When either of the String arguments is the null reference an System.ArgumentOutOfRangeException shall be thrown if the corresponding index is non-zero. The result of comparing any System.String (including the empty string) to a null reference is greater than zero. The result of comparing two null references is zero. Upper case letters evaluate greater than their lower case equivalents. The method uses the culture of the current thread to determine the ordering of individual characters. The two strings are compared on a character-by-character basis. |
public System.Int32 CompareTo(System.Object value) Returns the sort order of the current instance compared to the specified object. Parameter value: The System.Object to compare to the current instance. Returns: A System.Int32 containing a value that reflects the sort order of the current instance as compared to value . The following table defines the conditions under which the returned value is a negative number, zero, or a positive number. Throws: : value is not a System.String. value is required to be a System.String object. The result of comparing any System.String (including the empty string) to a null reference is greater than zero. The result of comparing two null references is zero. Upper case letters evaluate greater than their lower case equivalents. The method uses the culture of the current thread to determine the ordering of individual characters. The two strings are compared on a character-by-character basis. This method is implemented to support the System.IComparable interface. |
public static System.String Concat(System.Object arg0, System.Object arg1) Concatenates the System.String representations of two specified objects. Parameter arg0: The first System.Object to concatenate. Parameter arg1: The second System.Object to concatenate. Returns: The concatenated System.String representation of the values of arg0 and arg1. System.String.Empty is used in place of any null argument. This version of System.String.Concat(System.Object) is equivalent to System.String.Concat(System.Object)( arg0.ToString(), arg1.ToString () ). If either of the arguments is an array reference, the method concatenates a string representing that array, instead of its members (for example, System.String )[]. Example: The following example demonstrates concatenating two objects. using System;
public class StringConcatExample {
public static void Main() {
string str = String.Concat( 'c', 32 );
Console.WriteLine( "The concatenated Objects are: {0}", str );
}
}
The output is The concatenated Objects are: c32 |
public static System.String Concat(System.Object arg0, System.Object arg1, System.Object arg2) Concatenates the System.String representations of three specified objects, in order provided. Parameter arg0: The first System.Object to concatenate. Parameter arg1: The second System.Object to concatenate. Parameter arg2: The third System.Object to concatenate. Returns: The concatenated System.String representations of the values of arg0, arg1, and arg2. This method concatenates the values returned by the System.String.ToString methods on every argument. System.String.Empty is used in place of any null argument. This version of System.String.Concat(System.Object) is equivalent to String.Concat( arg0.ToString(), arg1.ToString(), arg2.ToString () ). Example: The following example demonstrates concatenating three objects. using System;
public class StringConcatExample {
public static void Main() {
string str = String.Concat( 'c', 32, "String" );
Console.WriteLine( "The concatenated Objects are: {0}", str );
}
}
The output is The concatenated Objects are: c32String |
public static System.String Concat(System.Object[] args) Concatenates the System.String representations of the elements in an array of System.Object instances. Parameter args: An array of System.Object instances to concatenate. Returns: The concatenated System.String representations of the values of the elements in args. Throws: : args is a null reference. This method concatenates the values returned by the System.String.ToString methods on every object in the args array. System.String.Empty is used in place of any null reference in the array. Example: The following example demonstrates concatenating an array of objects. using System;
public class StringConcatExample {
public static void Main() {
string str = String.Concat( 'c', 32, "String" );
Console.WriteLine( "The concatenated Object array is: {0}", str );
}
}
The output is The concatenated Object array is: c32String |
public static System.String Concat(System.String str0, System.String str1) Concatenates two specified instances of System.String. Parameter str0: The first System.String to concatenate. Parameter str1: The second System.String to concatenate. Returns: A System.String containing the concatenation of str0 and str1. System.String.Empty is used in place of any null argument. Example: The following example demonstrates concatenating two strings. using System;
public class StringConcatExample {
public static void Main() {
string str = String.Concat( "one", "two" );
Console.WriteLine( "The concatenated strings are: {0}", str );
}
}
The output is The concatenated strings are: onetwo |
public static System.String Concat(System.String str0, System.String str1, System.String str2) Concatenates three specified instances of System.String. Parameter str0: The first System.String to concatenate. Parameter str1: The second System.String to concatenate. Parameter str2: The third System.String to concatenate. Returns: A System.String containing the concatenation of str0, str1, and str2. System.String.Empty is used in place of any null argument. Example: The following example demonstrates concatenating three strings. using System;
public class StringConcatExample {
public static void Main() {
string str = String.Concat( "one", "two", "three" );
Console.WriteLine( "The concatenated strings are: {0}", str );
}
}
The output is The concatenated strings are: onetwothree |
public static System.String Concat(System.String[] values) Concatenates the elements of a specified array. Parameter values: An array of System.String instances to concatenate. Returns: A System.String containing the concatenated elements of values. Throws: : values is a null reference. System.String.Empty is used in place of any null reference in the array. Example: The following example demonstrates concatenating an array of strings. using System;
public class StringConcatExample {
public static void Main() {
string str = String.Concat( "one", "two", "three", "four", "five" );
Console.WriteLine( "The concatenated String array is: {0}", str );
}
}
The output is The concatenated String array is: onetwothreefourfive |
public static System.String Copy(System.String str) Creates a new instance of System.String with the same value as a specified instance of System.String. Parameter str: The System.String to be copied. Returns: A new System.String with the same value as str. Throws: : str is a null reference. Example: The following example demonstrates copying strings. using System;
public class StringCopyExample {
public static void Main() {
string strA = "string";
Console.WriteLine( "The initial string, strA, is '{0}'.", strA );
string strB = String.Copy( strA );
strA = strA.ToUpper();
Console.WriteLine( "The copied string, strB, before strA.ToUpper, is '{0}'.", strB );
Console.WriteLine( "The initial string after StringCopy and ToUpper, is '{0}'.", strA );
Console.WriteLine( "The copied string, strB, after strA.ToUpper, is '{0}'.", strB );
}
}
The output is The initial string, strA, is 'string'. The copied string, strB, before strA.ToUpper, is 'string'. The initial string after StringCopy and ToUpper, is 'STRING'. The copied string, strB, after strA.ToUpper, is 'string'. |
public System.Void CopyTo(System.Int32 sourceIndex, System.Char[] destination, System.Int32 destinationIndex, System.Int32 count) Copies a specified number of characters from a specified position in the current System.String instance to a specified position in a specified array of Unicode characters. Parameter sourceIndex: A System.Int32 containing the index of the current instance from which to copy. Parameter destination: An array of Unicode characters. Parameter destinationIndex: A System.Int32 containing the index of an array element in destination to copy. Parameter count: A System.Int32 containing the number of characters in the current instance to copy to destination. Throws: : destination is a null reference. Throws: : sourceIndex, destinationIndex, or count is negative -or- count is greater than the length of the substring from startIndex to the end of the current instance -or- count is greater than the length of the subarray from destinationIndex to the end of destination Example: The following example demonstrates copying characters from a string to a Unicode character array. using System;
public class StringCopyToExample {
public static void Main() {
string str = "this is the new string";
Char[] cAry = {'t','h','e',' ','o','l','d'};
Console.WriteLine( "The initial string is '{0}'", str );
Console.Write( "The initial character array is: '" );
foreach( Char c in cAry)
Console.Write( c );
Console.WriteLine( "'" );
str.CopyTo( 12, cAry, 4, 3 );
Console.Write( "The character array after CopyTo is: '" );
foreach( Char c in cAry)
Console.Write( c );
Console.WriteLine("'");
}
}
The output is The initial string is 'this is the new string' The initial character array is: 'the old' The character array after CopyTo is: 'the new' |
public System.Boolean EndsWith(System.String value) Returns a System.Boolean value that indicates whether the ending characters of the current instance match the specified System.String. Parameter value: A System.String to match. Returns: true if the end of the current instance is equal to value; false if value is not equal to the end of the current instance or is longer than the current instance. Throws: : value is a null reference. This method compares value with the substring at the end of the current instance that has a same length as value. The comparison is case-sensitive. Example: The following example demonstrates determining whether the current instance ends with a specified string. using System;
public class StringEndsWithExample {
public static void Main() {
string str = "One string to compare";
Console.WriteLine( "The given string is '{0}'", str );
Console.Write( "The given string ends with 'compare'? " );
Console.WriteLine( str.EndsWith( "compare" ) );
Console.Write( "The given string ends with 'Compare'? " );
Console.WriteLine( str.EndsWith( "Compare" ) );
}
}
The output is The given string is 'One string to compare' The given string ends with 'compare'? True The given string ends with 'Compare'? False |
public System.Boolean Equals(System.Object obj) Determines whether the current instance and the specified object have the same value. Parameter obj: A System.Object. Returns: true if obj is a System.String and its value is the same as the value of the current instance; otherwise, false. Throws: : The current instance is a null reference. This method checks for value equality. This comparison is case-sensitive. This method overrides System.Object.Equals(System.Object) . Example: The following example demonstrates checking to see if an object is equal to the current instance. using System;
public class StringEqualsExample {
public static void Main() {
string str = "A string";
Console.WriteLine( "The given string is '{0}'", str );
Console.Write( "The given string is equal to 'A string'? " );
Console.WriteLine( str.Equals( "A string" ) );
Console.Write( "The given string is equal to 'A String'? " );
Console.WriteLine( str.Equals( "A String" ) );
}
}
The output is The given string is 'A string' The given string is equal to 'A string'? True The given string is equal to 'A String'? False |
public static System.Boolean Equals(System.String a, System.String b) Determines whether two specified System.String objects have the same value. Parameter a: A System.String or a null reference. Parameter b: A System.String or a null reference. Returns: true if the value of a is the same as the value of b; otherwise, false. The comparison is case-sensitive. Example: The following example demonstrates checking to see if two strings are equal. using System;
public class StringEqualsExample {
public static void Main() {
string strA = "A string";
string strB = "a string";
string strC = "a string";
Console.Write( "The string '{0}' is equal to the string '{1}'? ", strA, strB );
Console.WriteLine( String.Equals( strA, strB ) );
Console.Write( "The string '{0}' is equal to the string '{1}'? ", strC, strB );
Console.WriteLine( String.Equals( strC, strB ) );
}
}
The output is The string 'A string' is equal to the string 'a string'? False The string 'a string' is equal to the string 'a string'? True |
public static System.String Format(System.String format, System.Object[] args) Replaces the format specification in a specified System.String with the textual equivalent of the value of a corresponding System.Object instance in a specified array. Parameter format: A System.String containing zero or more format specifications. Parameter args: A System.Object array containing the objects to be formatted. Returns: A System.String containing a copy of format in which the format specifications have been replaced by the System.String equivalent of the corresponding instances of System.Object in args. Throws: : format or args is a null reference. Throws: : format is invalid. -or- The number indicating an argument to be formatted is less than zero, or greater than or equal to the length of the args array. If an object referenced in the format string is a null reference, an empty string is used in its place. This version of System.String.Format(System.String,System.Object) is equivalent to System.String.Format(System.String,System.Object)( null, format, args ). For more information on the format specification see the System.String class overview. Example: The following example demonstrates the System.String.Format(System.String,System.Object) method.
using System;
public class StringFormat {
public static void Main() {
Console.WriteLine( String.Format("The winning numbers were {0:000} {1:000} {2:000} {3:000} {4:000} today.", 5, 10, 11, 37, 42) );
Console.WriteLine( "The winning numbers were {0, -6}{1, -6}{2, -6}{3, -6}{4, -6} today.", 5, 10, 11, 37, 42 );
}
}
The output is
The winning numbers were 005 010 011 037 042 today.
The winning numbers were 5 10 11 37 42 today.
|
public static System.String Format(System.String format, System.Object arg0) Replaces the format specification in a provided System.String with a specified textual equivalent of the value of a specified System.Object instance. Parameter format: A System.String containing zero or more format specifications. Parameter arg0: A System.Object to be formatted. Returns: A copy of format in which the first format specification has been replaced by the formatted System.String equivalent of the arg0. Throws: : format is a null reference. Throws: : The format specification in format is invalid. -or- The number indicating an argument to be formatted is less than zero, or greater than or equal to the number of provided objects to be formatted (1). This version of System.String.Format(System.String,System.Object) is equivalent to String.Format( null , format, new Object[] {arg0} ). For more information on the format specification see the System.String class overview. Example: The following example demonstrates the System.String.Format(System.String,System.Object) method.
using System;
public class StringFormat {
public static void Main() {
Console.WriteLine(String.Format("The high temperature today was {0:###} degrees.", 88));
Console.WriteLine("The museum had {0,-6} visitors today.", 88);
}
}
The output is
The high temperature today was 88 degrees.
The museum had 88 visitors today.
|
public static System.String Format(System.String format, System.Object arg0, System.Object arg1) Replaces the format specification in a specified System.String with the textual equivalent of the value of two specified System.Object instances. Parameter format: A System.String containing zero or more format specifications. Parameter arg0: A System.Object to be formatted. Can be a null reference. Parameter arg1: A System.Object to be formatted. Can be a null reference. Returns: A System.String containing a copy of format in which the format specifications have been replaced by the System.String equivalent of arg0 and arg1. Throws: : format is a null reference. Throws: : format is invalid. -or- The number indicating an argument to be formatted is less than zero, or greater than or equal to the number of provided objects to be formatted (2). If an object referenced in the format string is a null reference, an empty string is used in its place. This version of System.String.Format(System.String,System.Object) is equivalent to String.Format( null, format, new Object[] {arg0, arg1} ). For more information on the format specification see the System.String class overview. Example: The following example demonstrates the System.String.Format(System.String,System.Object) method. using System;
public class StringFormat {
public static void Main() {
Console.WriteLine( String.Format("The temperature today oscillated between {0:####} and {1:####} degrees.", 78, 100) );
Console.WriteLine( String.Format("The temperature today oscillated between {0:0000} and {1:0000} degrees.", 78, 100) );
Console.WriteLine( "The temperature today oscillated between {0, -4} and {1, -4} degrees.", 78, 100 );
}
}
The output is
The temperature today oscillated between 78 and 100 degrees.
The temperature today oscillated between 0078 and 0100 degrees.
The temperature today oscillated between 78 and 100 degrees.
|
public static System.String Format(System.String format, System.Object arg0, System.Object arg1, System.Object arg2) Replaces the format specification in a specified System.String with the textual equivalent of the value of three specified System.Object instances. Parameter format: A System.String containing zero or more format specifications. Parameter arg0: The first System.Object to be formatted. Can be a null reference. Parameter arg1: The second System.Object to be formatted. Can be a null reference. Parameter arg2: The third System.Object to be formatted. Can be a null reference. Returns: A System.String containing a copy of format in which the first, second, and third format specifications have been replaced by the System.String equivalent of arg0, arg1, and arg2. Throws: : format is a null reference. Throws: : format is invalid. -or- The number indicating an argument to be formatted is less than zero, or greater than or equal to the number of provided objects to be formatted (3). If an object referenced in the format string is a null reference, an empty string is used in its place. This version of System.String.Format(System.String,System.Object) is equivalent to String.Format( null, format, new Object[] {arg0, arg1, arg2} ). For more information on the format specification see the System.String class overview. Example: The following example demonstrates the System.String.Format(System.String,System.Object) method.
using System;
public class StringFormat {
public static void Main() {
Console.WriteLine(String.Format("The temperature today oscillated between {0:###} and {1:###} degrees. The average temperature was {2:000} degrees.", 78, 100, 91));
Console.WriteLine("The temperature today oscillated between {0, 4} and {1, 4} degrees. The average temperature was {2, 4} degrees.", 78, 100, 91);
}
}
The output is
The temperature today oscillated between 78 and 100 degrees. The average temperature was 091 degrees.
The temperature today oscillated between 78 and 100 degrees. The average temperature was 91 degrees.
|
public static System.String Format(System.IFormatProvider provider, System.String format, System.Object[] args) Replaces the format specification in a specified System.String with the culture-specific textual equivalent of the value of a corresponding System.Object instance in a specified array. Parameter provider: A System.IFormatProvider interface that supplies an object that provides culture-specific formatting information. Can be a null reference. Parameter format: A System.String containing zero or more format specifications. Parameter args: A System.Object array to be formatted. Returns: A System.String containing a copy of format in which the format specifications have been replaced by the System.String equivalent of the corresponding instances of System.Object in args . Throws: : format or args is a null reference. Throws: : format is invalid. -or- The number indicating an argument to be formatted (N) is less than zero, or greater than or equal to the length of the args array. If an object referenced in the format string is a null reference, an empty string is used in its place. The format parameter string is embedded with zero or more format specifications of the form, {N [, M ][: formatString ]}, where N is a zero-based integer indicating the argument to be formatted, M is an optional integer indicating the width of the region to contain the formatted value, and formatString is an optional string of formatting codes. For more information on the format specification see the System.String class overview. |
public System.CharEnumerator GetEnumerator() Retrieves an object that can iterate through the individual characters in the current instance. Returns: A System.CharEnumerator object. This method is required by programming languages that support the System.Collections.IEnumerator interface to iterate through members of a collection. |
public System.Int32 GetHashCode() Generates a hash code for the current instance. Returns: A System.Int32 containing the hash code for this instance. The algorithm used to generate the hash code is unspecified. This method overrides System.Object.GetHashCode. |
public System.Int32 IndexOf(System.Char value) Returns the index of the first occurrence of a specified Unicode character in the current instance. Parameter value: A Unicode character. Returns: A System.Int32 containing a positive value equal to the index of the first occurrence of value character in the current instance; otherwise, -1 if value was not found. This method is case-sensitive. |
public System.Int32 IndexOf(System.Char value, System.Int32 startIndex) Returns the index of the first occurrence of a specified Unicode character in the current instance, with the search starting from a specified index. Parameter value: A Unicode character. Parameter startIndex: A System.Int32 containing the index of the current instance from which to start searching. Returns: A System.Int32 containing a positive value equal to the index of the first occurrence of value in the current instance; otherwise, -1 if value was not found. Throws: : startIndex is less than zero or greater than the length of the current instance. This method is case-sensitive. Example: The following example demonstrates the System.String.IndexOf(System.Char) method. using System;
public class StringIndexOf {
public static void Main() {
String str = "This is the string";
Console.WriteLine( "Searching for the index of 'h' starting from index 0 yields {0}.", str.IndexOf( 'h', 0 ) );
Console.WriteLine( "Searching for the index of 'h' starting from index 10 yields {0}.", str.IndexOf( 'h', 10 ) );
}
}
The output is Searching for the index of 'h' starting from index 0 yields 1. Searching for the index of 'h' starting from index 10 yields -1. |
public System.Int32 IndexOf(System.Char value, System.Int32 startIndex, System.Int32 count) Returns the index of the first occurrence of a specified Unicode character in the current instance, with the search over the specified range starting at the provided index. Parameter value: A Unicode character. Parameter startIndex: A System.Int32 containing the index of the current instance from which to start searching. Parameter count: A System.Int32 containing the range of the current instance at which to end searching. Returns: A System.Int32 containing a positive value equal to the index of the first occurrence of value in the current instance; otherwise, -1 if value was not found. Throws: : startIndex or count is negative -or- startIndex + count is greater than the length of the current instance. The search begins at startIndex and continues until startIndex + count - 1 is reached. The character at startIndex + count is not included in the search. This method is case-sensitive. |
public System.Int32 IndexOf(System.String value) Returns the index of the first occurrence of a specified System.String in the current instance. Parameter value: The System.String to seek. Returns: A System.Int32 that indicates the result of the search for value in the current instance as follows: Throws: : value is a null reference. The search begins at the first character of the current instance. The search is case-sensitive, culture-sensitive, and the culture of the current thread is used. Example: The following example demonstrates the System.String.IndexOf(System.Char) method. using System;
public class StringIndexOf {
public static void Main() {
String str = "This is the string";
Console.WriteLine( "Searching for the index of \"is\" yields {0,2}.", str.IndexOf( "is" ) );
Console.WriteLine( "Searching for the index of \"Is\" yields {0,2}.", str.IndexOf( "Is" ) );
Console.WriteLine( "Searching for the index of \"\" yields {0,2}.", str.IndexOf( "" ) );
}
}
The output is Searching for the index of "is" yields 2. Searching for the index of "Is" yields -1. Searching for the index of "" yields 0. |
public System.Int32 IndexOf(System.String value, System.Int32 startIndex) Returns the index of the first occurrence of a specified System.String in the current instance, with the search starting from a specified index. Parameter value: The System.String to seek. Parameter startIndex: A System.Int32 containing the index of the current instance from which to start searching. Returns: A System.Int32 that indicates the result of the search for value in the current instance as follows: Throws: : value is a null reference. Throws: : startIndex is greater than the length of the current instance. This method is case-sensitive. |
public System.Int32 IndexOf(System.String value, System.Int32 startIndex, System.Int32 count) Returns the index of the first occurrence of a specified System.String in the current instance, with the search over the specified range starting at the provided index. Parameter value: The System.String to seek. Parameter startIndex: A System.Int32 containing the index of the current instance from which to start searching. Parameter count: A System.Int32 containing the range of the current instance at which to end searching. Returns: A System.Int32 that indicates the result of the search for value in the current instance as follows: Throws: : value is a null reference. Throws: : startIndex or count is negative -or- startIndex + count is greater than the length of the current instance. The search begins at startIndex and continues until startIndex + count - 1 is reached. The character at startIndex + count is not included in the search. This method is case-sensitive. |
public System.Int32 IndexOfAny(System.Char[] anyOf) Reports the index of the first occurrence in the current instance of any character in a specified array of Unicode characters. Parameter anyOf: An array of Unicode characters. Returns: The index of the first occurrence of an element of anyOf in the current instance; otherwise, -1 if no element of anyOf was found. Throws: : anyOf is a null reference. This method is case-sensitive. |
public System.Int32 IndexOfAny(System.Char[] anyOf, System.Int32 startIndex) Returns the index of the first occurrence of any element in a specified array of Unicode characters in the current instance, with the search starting from a specified index. Parameter anyOf: An array of Unicode characters. Parameter startIndex: A System.Int32 containing the index of the current instance from which to start searching. Returns: A System.Int32 containing a positive value equal to the index of the first occurrence of an element of anyOf in the current instance; otherwise, -1 if no element of anyOf was found. Throws: : anyOf is a null reference. Throws: : startIndex is greater than the length of the current instance This method is case-sensitive. |
public System.Int32 IndexOfAny(System.Char[] anyOf, System.Int32 startIndex, System.Int32 count) Returns the index of the first occurrence of any element in a specified Array of Unicode characters in the current instance, with the search over the specified range starting from the provided index. Parameter anyOf: An array containing the Unicode characters to seek. Parameter startIndex: A System.Int32 containing the index of the current instance from which to start searching. Parameter count: A System.Int32 containing the range of the current instance at which to end searching. Returns: A System.Int32 containing a positive value equal to the index of the first occurrence of an element of anyOf in the current instance; otherwise, -1 if no element of anyOf was found. Throws: : anyOf is a null reference. Throws: : startIndex or count is negative. -or- startIndex + count is greater than the length of the current instance. The search begins at startIndex and continues until startIndex + count - 1. The character at startIndex + count is not included in the search. This method is case-sensitive. |
public System.String Insert(System.Int32 startIndex, System.String value) Returns a System.String equivalent to the current instance with a specified System.String inserted at the specified position. Parameter startIndex: A System.Int32 containing the index of the insertion. Parameter value: The System.String to insert. Returns: A new System.String that is equivalent to the current string with value inserted at index startIndex. Throws: : value is a null reference. Throws: : startIndex is greater than the length of the current instance. In the new string returned by this method, the first character of value is at startIndex, and all characters in the current string from startIndex to the end are inserted in the new string after the last character of value. |
public static System.String Intern(System.String str) Retrieves the system's reference to a specified System.String. Parameter str: A System.String. Returns: The System.String reference to str. Throws: : str is a null reference. Instances of each unique literal string constant declared in a program, as well as any unique instance of System.String you add programmatically are kept in a table, called the "intern pool". The intern pool conserves string storage. If a literal string constant is assigned to several variables, each variable is set to reference the same constant in the intern pool instead of referencing several different instances of System.String that have identical values. This method looks up a specified string in the intern pool. If the string exists, a reference to it is returned. If it does not exist, an instance equal to the specified string is added to the intern pool and a reference that instance is returned. Example: The following example demonstrates the System.String.Intern(System.String) method. using System;
using System.Text;
public class StringExample {
public static void Main() {
String s1 = "MyTest";
String s2 = new StringBuilder().Append("My").Append("Test").ToString();
String s3 = String.Intern(s2);
Console.WriteLine(Object.ReferenceEquals(s1, s2)); //different
Console.WriteLine(Object.ReferenceEquals(s1, s3)); //the same
}
}
The output is False True |
public static System.String IsInterned(System.String str) Retrieves a reference to a specified System.String. Parameter str: A System.String. Returns: A System.String reference to str if it is in the system's intern pool; otherwise, a null reference. Throws: : str is a null reference. Instances of each unique literal string constant declared in a program, as well as any unique instance of System.String you add programmatically are kept in a table, called the "intern pool". The intern pool conserves string storage. If a literal string constant is assigned to several variables, each variable is set to reference the same constant in the intern pool instead of referencing several different instances of System.String that have identical values. This method does not return a System.Boolean value, but can still be used where a System.Boolean is needed. Example: The following example demonstrates the System.String.IsInterned(System.String) method. using System;
using System.Text;
public class StringExample {
public static void Main() {
String s1 = new StringBuilder().Append("My").Append("Test").ToString();
Console.WriteLine(String.IsInterned(s1) != null);
}
}
The output is True |
public static System.String Join(System.String separator, System.String[] value) Concatenates the elements of a specified System.String array, inserting a separator string between each element pair and yielding a single concatenated string. Parameter separator: A System.String. Parameter value: A System.String array. Returns: A System.String consisting of the elements of value separated by instances of the separator string. Throws: : value is a null reference. Example: The following example demonstrates the System.String.Join(System.String,System.String[]) method. using System;
public class StringJoin {
public static void Main() {
String[] strAry = { "Red" , "Green" , "Blue" };
Console.WriteLine( String.Join( " :: ", strAry ) );
}
}
The output is Red :: Green :: Blue |
public static System.String Join(System.String separator, System.String[] value, System.Int32 startIndex, System.Int32 count) Concatenates a specified separator System.String between the elements of a specified System.String array, yielding a single concatenated string. Parameter separator: A System.String. Parameter value: A System.String array. Parameter startIndex: A System.Int32 containing the first array element in value to join. Parameter count: A System.Int32 containing the number of elements in value to join. Returns: A System.String consisting of the strings in value joined by separator. Returns System.String.Empty if count is zero, value has no elements, or separator and all the elements of value are Empty. Throws: : startIndex plus count is greater than the number of elements in value. Example: The following example demonstrates the System.String.Join(System.String,System.String[]) method. using System;
public class StringJoin {
public static void Main() {
String[] strAry = { "Red" , "Green" , "Blue" };
Console.WriteLine( String.Join( " :: ", strAry, 1, 2 ) );
}
}
The output is Green :: Blue |
public System.Int32 LastIndexOf(System.String value, System.Int32 startIndex) Returns the index of the last occurrence of a specified System.String within the current instance. Parameter value: A System.String . Parameter startIndex: A System.Int32 containing the index of the current instance from which to start searching. Returns: A System.Int32 that indicates the result of the search for value in the current instance as follows: Throws: : value is a null reference. Throws: : startIndex is less than zero or greater than or equal to the length of the current instance. This method searches for the last occurrence of the specified System.String between the start of the string and the indicated index. This method is case-sensitive. |
public System.Int32 LastIndexOf(System.String value, System.Int32 startIndex, System.Int32 count) Returns the index of the last occurrence of a specified System.String in the provided range of the current instance. Parameter value: The substring to search for. Parameter startIndex: A System.Int32 containing the index of the current instance from which to start searching. Parameter count: A System.Int32 containing the range of the current instance at which to end searching. Returns: A System.Int32 that indicates the result of the search for value in the current instance as follows: Throws: : value is a null reference. Throws: : startIndex or count is less than zero. -or- startIndex - count is smaller than -1. The search begins at startIndex and continues until startIndex - count + 1. This method is case-sensitive. |
public System.Int32 LastIndexOf(System.String value) Returns the index of the last occurrence of a specified System.String within the current instance. Parameter value: A System.String . Returns: A System.Int32 that indicates the result of the search for value in the current instance as follows: Throws: : value is a null reference. The search is case-sensitive. |
public System.Int32 LastIndexOf(System.Char value, System.Int32 startIndex, System.Int32 count) Returns the index of the last occurrence of a specified character in the provided range of the current instance. Parameter value: A Unicode character to locate. Parameter startIndex: A System.Int32 containing the index of the current instance from which to start searching. Parameter count: A System.Int32 containing the range of the current instance at which to end searching. Returns: A System.Int32 containing the index of the last occurrence of value in the current instance if found between startIndex and (startIndex - count + 1); otherwise, -1. Throws: : value is a null reference. Throws: : startIndex or count is less than zero. -or- startIndex - count is less than -1. This method is case-sensitive. |
public System.Int32 LastIndexOf(System.Char value, System.Int32 startIndex) Returns the index of the last occurrence of a specified character within the current instance. Parameter value: A Unicode character to locate. Parameter startIndex: A System.Int32 containing the index in the current instance from which to begin searching. Returns: A System.Int32 containing the index of the last occurrence of value in the current instance, if found; otherwise, -1. Throws: : value is a null reference. Throws: : startIndex is less than zero or greater than the length of the current instance. This method searches for the last occurrence of the specified character between the start of the string and the indicated index. This method is case-sensitive. Example: The following example demonstrates the System.String.LastIndexOf(System.Char) method. using System;
public class StringLastIndexOfTest {
public static void Main() {
String str = "aa bb cc dd";
Console.WriteLine( str.LastIndexOf('d', 8) );
Console.WriteLine( str.LastIndexOf('b', 8) );
}
}
The output is -1 4 |
public System.Int32 LastIndexOf(System.Char value) Returns the index of the last occurrence of a specified character within the current instance. Parameter value: The Unicode character to locate. Returns: A System.Int32 containing the index of the last occurrence of value in the current instance, if found; otherwise, -1. This method is case-sensitive. |
public System.Int32 LastIndexOfAny(System.Char[] anyOf) Returns the index of the last occurrence of any element of a specified array of characters in the current instance. Parameter anyOf: An array of Unicode characters. Returns: A System.Int32 containing the index of the last occurrence of any element of anyOf in the current instance, if found; otherwise, -1. Throws: : anyOf is a null reference. This method is case-sensitive. |
public System.Int32 LastIndexOfAny(System.Char[] anyOf, System.Int32 startIndex) Returns the index of the last occurrence of any element of a specified array of characters in the current instance. Parameter anyOf: An array of Unicode characters. Parameter startIndex: A System.Int32 containing the index of the current instance from which to start searching. Returns: A System.Int32 containing the index of the last occurrence of any element of anyOf in the current instance, if found; otherwise, -1. Throws: : anyOf is a null reference. Throws: : startIndex is less than zero or greater than or equal to the length of the current instance. This method searches for the last occurrence of the specified characters between the start of the string and the indicated index. This method is case-sensitive. |
public System.Int32 LastIndexOfAny(System.Char[] anyOf, System.Int32 startIndex, System.Int32 count) Returns the index of the last occurrence of any of specified characters in the provided range of the current instance. Parameter anyOf: An array of Unicode characters. Parameter startIndex: A System.Int32 containing the index of the current instance from which to start searching. Parameter count: A System.Int32 containing the range of the current instance at which to end searching. Returns: A System.Int32 containing the index of the last occurrence of any element of anyOf if found between startIndex and (startIndex - count + 1); otherwise, -1. Throws: : anyOf is a null reference. Throws: : startIndex or count is less than zero. -or- startIndex - count is smaller than -1. The search begins at startIndex and continues until startIndex - count + 1. The character at startIndex - count is not included in the search. This method is case-sensitive. |
public static System.Boolean op_Equality(System.String a, System.String b) Returns a System.Boolean value indicating whether the two specified string values are equal to each other. Parameter a: The first System.String to compare. Parameter b: The second System.String to compare. Returns: true if a and b represent the same string value; otherwise, false. |
public static System.Boolean op_Inequality(System.String a, System.String b) Returns a System.Boolean value indicating whether the two string values are not equal to each other. Parameter a: The first System.String to compare. Parameter b: The second System.String to compare. Returns: true if a and b do not represent the same string value; otherwise, false. |
public System.String PadLeft(System.Int32 totalWidth) Right-aligns the characters in the current instance, padding with spaces on the left, for a specified total length. Parameter totalWidth: A System.Int32 containing the number of characters in the resulting string. Returns: A new System.String that is equivalent to the current instance right-aligned and padded on the left with as many spaces as needed to create a length of totalWidth. If totalWidth is less than the length of the current instance, returns a new System.String that is identical to the current instance. Throws: : totalWidth is less than zero. A space in Unicode format is defined as the hexadecimal value 0x20. |
public System.String PadLeft(System.Int32 totalWidth, System.Char paddingChar) Right-aligns the characters in the current instance, padding on the left with a specified Unicode character, for a specified total length. Parameter totalWidth: A System.Int32 containing the number of characters in the resulting string. Parameter paddingChar: A System.Char that specifies the padding character to use. Returns: A new System.String that is equivalent to the current instance right-aligned and padded on the left with as many paddingChar characters as needed to create a length of totalWidth . If totalWidth is less than the length of the current instance, returns a new System.String that is identical to the current instance. Throws: : totalWidth is less than zero. |
public System.String PadRight(System.Int32 totalWidth, System.Char paddingChar) Left-aligns the characters in the current instance, padding on the right with a specified Unicode character, for a specified total number of characters. Parameter totalWidth: A System.Int32 containing the number of characters in the resulting string. Parameter paddingChar: A System.Char that specifies the padding character to use. Returns: A new System.String that is equivalent to the current instance left aligned and padded on the right with as many paddingChar characters as needed to create a length of totalWidth. If totalWidth is less than the length of the current instance, returns a new System.String that is identical to the current instance. Throws: : totalWidth is less than zero. |
public System.String PadRight(System.Int32 totalWidth) Left-aligns the characters in the current instance, padding with spaces on the right, for a specified total number of characters. Parameter totalWidth: A System.Int32 containing the number of characters in the resulting string. Returns: A new System.String that is equivalent to this instance left aligned and padded on the right with as many spaces as needed to create a length of totalWidth. If totalWidth is less than the length of the current instance, returns a new System.String that is identical to the current instance. Throws: : totalWidth is less than zero. |
public System.String Remove(System.Int32 startIndex, System.Int32 count) Deletes a specified number of characters from the current instance beginning at a specified index. Parameter startIndex: A System.Int32 containing the index of the current instance from which to start deleting characters. Parameter count: A System.Int32 containing the number of characters to delete. Returns: A new System.String that is equivalent to the current instance without the specified range characters. Throws: : startIndex or count is less than zero. -or- startIndex plus count is greater than the length of the current instance. |
public System.String Replace(System.String oldValue, System.String newValue) Replaces all instances of a specified substring within the current instance with another specified string. Parameter oldValue: A System.String containing the string value to be replaced. Parameter newValue: A System.String containing the string value to replace all occurrences of oldValue. Can be a null reference. Returns: A System.String equivalent to the current instance with all occurrences of oldValue replaced with newValue. If the replacement value is a null reference, the specified substring is removed. |
public System.String Replace(System.Char oldChar, System.Char newChar) Replaces all instances of a specified Unicode character with another specified Unicode character. Parameter oldChar: The Unicode character to be replaced. Parameter newChar: The Unicode character to replace all occurrences of oldChar. Returns: A System.String equivalent to the current instance with all occurrences of oldChar replaced with NewChar. |
public System.String[] Split(System.Char[] separator) Returns substrings of the current instance that are delimited by the specified characters. Parameter separator: A System.Char array of delimiters. Can be a null reference. Returns: A System.String array containing the results of the split operation as follows: System.String.Empty is returned for any substring where two delimiters are adjacent or a delimiter is found at the beginning or end of the current instance. Delimiter characters are not included in the substrings. |
public System.String[] Split(System.Char[] separator, System.Int32 count) Returns substrings of the current instance that are delimited by the specified characters. Parameter separator: An array of Unicode characters that delimit the substrings in the current instance, an empty array containing no delimiters, or a null reference. Parameter count: A System.Int32 containing the maximum number of array elements to return. Returns: A System.String array containing the results of the split operation as follows: Throws: : count is negative. System.String.Empty is returned for any substring where two delimiters are adjacent or a delimiter is found at the beginning or end of the current instance. Delimiter characters are not included in the substrings. If there are more substrings in the current instance than the maximum specified number, the first count -1 elements of the array contain the first count - 1 substrings. The remaining characters in the current instance are returned in the last element of the array. |
public System.Boolean StartsWith(System.String value) Returns a System.Boolean value that indicates whether the start of the current instance matches the specified System.String. Parameter value: A System.String . Returns: true if the start of the current instance is equal to value; false if value is not equal to the start of the current instance or is longer than the current instance. Throws: : value is a null reference. This method compares value with the substring at the start of the current instance that has a length of value.Length. If value.Length is greater than the length of the current instance or the relevant substring of the current instance is not equal to value, this method returns false; otherwise, this method returns true . The comparison is case-sensitive. |
public System.String Substring(System.Int32 startIndex, System.Int32 length) Retrieves a substring from the current instance, starting from a specified index, continuing for a specified length. Parameter startIndex: A System.Int32 containing the index of the start of the substring in the current instance. Parameter length: A System.Int32 containing the number of characters in the substring. Returns: A System.String containing the substring of the current instance with the specified length that begins at the specified position. Returns System.String.Empty if startIndex is equal to the length of the current instance and length is zero. Throws: : length is greater than the length of the current instance. -or- startIndex or length is less than zero. |
public System.String Substring(System.Int32 startIndex) Retrieves a substring from the current instance, starting from a specified index. Parameter startIndex: A System.Int32 containing the index of the start of the substring in the current instance. Returns: A System.String equivalent to the substring that begins at startIndex of the current instance. Returns System.String.Empty if startIndex is equal to the length of the current instance. Throws: : startIndex is less than zero or greater than the length of the current instance. |
public System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() Implemented to support the System.Collections.IEnumerable interface. [Note: For more information, see System.Collections.IEnumerable.GetEnumerator.] |
public System.Char[] ToCharArray() Copies the characters in the current instance to a Unicode character array. Returns: A System.Char array whose elements are the individual characters of the current instance. If the current instance is an empty string, the array returned by this method is empty and has a zero length. |
public System.Char[] ToCharArray(System.Int32 startIndex, System.Int32 length) Copies the characters in a specified substring in the current instance to a Unicode character array. Parameter startIndex: A System.Int32 containing the index of the start of a substring in the current instance. Parameter length: A System.Int32 containing the length of the substring in the current instance. Returns: A System.Char array whose elements are the length number of characters in the current instance, starting from the index startIndex in the current instance. If the specified length is zero, the entire string is copied starting from the beginning of the current instance, and ignoring the value of startIndex. If the current instance is an empty string, the returned array is empty and has a zero length. Throws: : startIndex or length is less than zero. -or- startIndex plus length is greater than the length of the current instance. |
public System.String ToLower() Returns a copy of this System.String in lower case. Returns: A System.String in lower case.. This method takes into account the culture of the current thread. |
public System.String ToString() Returns a System.String representation of the value of the current instance. Returns: The current System.String. This method overrides System.Object.ToString. |
public System.String ToString(System.IFormatProvider provider) Returns this instance of String; no actual conversion is performed. Parameter provider: (Reserved) A System.IFormatProvider interface implementation which supplies culture-specific formatting information. Returns: This String. provider is reserved, and does not currently participate in this operation. |
public System.String ToUpper() Returns a copy of the current instance with all elements converted to upper case, using default properties. Returns: A new System.String in upper case. |
public System.String Trim(System.Char[] trimChars) Removes all occurrences of a set of characters provided in a character System.Array from the beginning and end of the current instance. Parameter trimChars: An array of Unicode characters. Can be a null reference. Returns: A new System.String equivalent to the current instance with the characters in trimChars removed from its beginning and end. If trimChars is a null reference, all of the white space characters are removed from the beginning and end of the current instance. |
public System.String Trim() Removes all occurrences of white space characters from the beginning and end of the current instance. Returns: A new System.String equivalent to the current instance after white space characters are removed from its beginning and end. |
public System.String TrimEnd(System.Char[] trimChars) Removes all occurrences of a set of characters specified in a Unicode character System.Array from the end of the current instance. Parameter trimChars: An array of Unicode characters. Can be a null reference. Returns: A new System.String equivalent to the current instance with characters in trimChars removed from its end. If trimChars is a null reference, white space characters are removed. |
public System.String TrimStart(System.Char[] trimChars) Removes all occurrences of a set of characters specified in a Unicode character array from the beginning of the current instance. Parameter trimChars: An array of Unicode characters or a null reference. Returns: A new System.String equivalent to the current instance with the characters in trimChars removed from its beginning. If trimChars is a null reference, white space characters are removed. |
| Functions inherited from System.Object: |
|---|
public virtual System.Boolean Equals(System.Object obj) Determines whether the specified System.Object is equal to the current instance. Parameter obj: The System.Object to compare with the current instance. Returns: true if obj is equal to the current instance; otherwise, false. The statements listed below are required to be true for all implementations of the System.Object.Equals(System.Object) method. In the list, x, y, and z represent non-null object references. See System.Object.GetHashCode for additional required behaviors pertaining to the System.Object.Equals(System.Object) method. Implementations of System.Object.Equals(System.Object) should not throw exceptions. The System.Object.Equals(System.Object) method tests for referential equality , which means that System.Object.Equals(System.Object) returns true if the specified instance of Object and the current instance are the same instance; otherwise, it returns false . An implementation of the System.Object.Equals(System.Object) method is shown in the following C# code: public virtual bool Equals(Object obj) { return this == obj; } For some kinds of objects, it is desirable to have System.Object.Equals(System.Object) test for value equality instead of referential equality. Such implementations of Equals return true if the two objects have the same "value", even if they are not the same instance. The definition of what constitutes an object's "value" is up to the implementer of the type, but it is typically some or all of the data stored in the instance variables of the object. For example, the value of a System.String is based on the characters of the string; the Equals method of the System.String class returns true for any two string instances that contain exactly the same characters in the same order. When the Equals method of a base class provides value equality, an override of Equals in a class derived from that base class should invoke the inherited implementation of Equals . It is recommended (but not required) that types overriding System.Object.Equals(System.Object) also override System.Object.GetHashCode. Hashtables cannot be relied on to work correctly if this recommendation is not followed. If your programming language supports operator overloading, and if you choose to overload the equality operator for a given type, that type should override the Equals method. Such implementations of the Equals method should return the same results as the equality operator. Following this guideline will help ensure that class library code using Equals (such as System.Collections.ArrayList and System.Collections.Hashtable ) behaves in a manner that is consistent with the way the equality operator is used by application code. If you are implementing a value type, you should follow these guidelines: For reference types, the guidelines are as follows: If you implement System.IComparable on a given type, you should override Equals on that type. The System.Object.Equals(System.Object) method is called by methods in collections classes that perform search operations, including the System.Array.IndexOf(System.Array,System.Object) method and the System.Collections.ArrayList.Contains(System.Object) method. Example: Example 1: The following example contains two calls to the default implementation of System.Object.Equals(System.Object) . using System;
class MyClass {
static void Main() {
Object obj1 = new Object();
Object obj2 = new Object();
Console.WriteLine(obj1.Equals(obj2));
obj1 = obj2;
Console.WriteLine(obj1.Equals(obj2));
}
}
The output is False True Example 2: The following example shows a Point class that overrides the System.Object.Equals(System.Object) method to provide value equality and a class Point3D, which is derived from Point . Because Point's override of System.Object.Equals(System.Object) is the first in the inheritance chain to introduce value equality, the Equals method of the base class (which is inherited from System.Object and checks for referential equality) is not invoked. However, Point3D.Equals invokes Point.Equals because Point implements Equals in a manner that provides value equality. using System;
public class Point: object {
int x, y;
public override bool Equals(Object obj) {
//Check for null and compare run-time types.
if (obj == null || GetType() != obj.GetType()) return false;
Point p = (Point)obj;
return (x == p.x) && (y == p.y);
}
public override int GetHashCode() {
return x ^ y;
}
}
class Point3D: Point {
int z;
public override bool Equals(Object obj) {
return base.Equals(obj) && z == ((Point3D)obj).z;
}
public override int GetHashCode() {
return base.GetHashCode() ^ z;
}
}
The Point.Equals method checks that the obj
argument is non-null and that it references an instance of the same type as this
object. If either of those checks fail, the method returns false. The
System.Object.Equals(System.Object) method uses
System.Object.GetType to determine whether
the run-time types of the two objects are identical. (Note that
typeof is not used here because it returns the static type.) If
instead the method had used a check of the form
In Point3D.Equals , the inherited Equals method is invoked before anything else is done; the inherited Equals method checks to see that obj is non-null, that obj is an instance of the same class as this object, and that the inherited instance variables match. Only when the inherited Equals returns true does the method compare the instance variables introduced in the subclass. Specifically, the cast to Point3D is not executed unless obj has been determined to be of type Point3D or a subclass of Point3D . Example 3: In the previous example, operator == (the equality operator) is used to compare the individual instance variables. In some cases, it is appropriate to use the System.Object.Equals(System.Object) method to compare instance variables in an Equals implementation, as shown in the following example: using System;
class Rectangle {
Point a, b;
public override bool Equals(Object obj) {
if (obj == null || GetType() != obj.GetType()) return false;
Rectangle r = (Rectangle)obj;
//Use Equals to compare instance variables
return a.Equals(r.a) && b.Equals(r.b);
}
public override int GetHashCode() {
return a.GetHashCode() ^ b.GetHashCode();
}
}
Example 4: In some languages, such as C#, operator overloading is supported. When a type overloads operator ==, it should also override the System.Object.Equals(System.Object) method to provide the same functionality. This is typically accomplished by writing the Equals method in terms of the overloaded operator ==. For example: using System;
public struct Complex {
double re, im;
public override bool Equals(Object obj) {
return obj is Complex && this == (Complex)obj;
}
public override int GetHashCode() {
return re.GetHashCode() ^ im.GetHashCode();
}
public static bool operator ==(Complex x, Complex y) {
return x.re == y.re && x.im == y.im;
}
public static bool operator !=(Complex x, Complex y) {
return !(x == y);
}
}
Because Complex is a C# struct (a value type), it is known that there will be no subclasses of Complex . Therefore, the System.Object.Equals(System.Object) method need not compare the GetType() results for each object, but can instead use the is operator to check the type of the obj parameter. |
public static System.Boolean Equals(System.Object objA, System.Object objB) Determines whether two object references are equal. Parameter objA: First object to compare. Parameter objB: Second object to compare. Returns: true if one or more of the following statements is true: otherwise returns false. This static method checks for null references before it calls objA.Equals(objB ) and returns false if either objA or objB is null. If the Equals(object obj) implementation throws an exception, this method throws an exception. Example: The following example demonstrates the System.Object.Equals(System.Object) method. using System;
public class MyClass {
public static void Main() {
string s1 = "Tom";
string s2 = "Carol";
Console.WriteLine("Object.Equals(\"{0}\", \"{1}\") => {2}",
s1, s2, Object.Equals(s1, s2));
s1 = "Tom";
s2 = "Tom";
Console.WriteLine("Object.Equals(\"{0}\", \"{1}\") => {2}",
s1, s2, Object.Equals(s1, s2));
s1 = null;
s2 = "Tom";
Console.WriteLine("Object.Equals(null, \"{1}\") => {2}",
s1, s2, Object.Equals(s1, s2));
s1 = "Carol";
s2 = null;
Console.WriteLine("Object.Equals(\"{0}\", null) => {2}",
s1, s2, Object.Equals(s1, s2));
s1 = null;
s2 = null;
Console.WriteLine("Object.Equals(null, null) => {2}",
s1, s2, Object.Equals(s1, s2));
}
}
The output is Object.Equals("Tom", "Carol") => False Object.Equals("Tom", "Tom") => True Object.Equals(null, "Tom") => False Object.Equals("Carol", null) => False Object.Equals(null, null) => True |
public System.Void Finalize() Allows a System.Object to perform cleanup operations before the memory allocated for the System.Object is automatically reclaimed. During execution, System.Object.Finalize is automatically called after an object becomes inaccessible, unless the object has been exempted from finalization by a call to System.GC.SuppressFinalize(System.Object). During shutdown of an application domain, System.Object.Finalize is automatically called on objects that are not exempt from finalization, even those that are still accessible. System.Object.Finalize is automatically called only once on a given instance, unless the object is re-registered using a mechanism such as System.GC.ReRegisterForFinalize(System.Object) and System.GC.SuppressFinalize(System.Object) has not been subsequently called. Conforming implementations of the CLI are required to make every effort to ensure that for every object that has not been exempted from finalization, the System.Object.Finalize method is called after the object becomes inaccessible. However, there may be some circumstances under which Finalize is not called. Conforming CLI implementations are required to explicitly specify the conditions under which Finalize is not guaranteed to be called. For example, Finalize might not be guaranteed to be called in the event of equipment failure, power failure, or other catastrophic system failures. In addition to System.GC.ReRegisterForFinalize(System.Object) and System.GC.SuppressFinalize(System.Object), conforming implementations of the CLI are allowed to provide other mechanisms that affect the behavior of System.Object.Finalize . Any mechanisms provided are required to be specified by the CLI implementation. The order in which the Finalize methods of two objects are run is unspecified, even if one object refers to the other. The thread on which Finalize is run is unspecified. Every implementation of System.Object.Finalize in a derived type is required to call its base type's implementation of Finalize . This is the only case in which application code calls System.Object.Finalize . The System.Object.Finalize implementation does nothing. A type should implement Finalize when it uses unmanaged resources such as file handles or database connections that must be released when the managed object that uses them is reclaimed. Because Finalize methods may be invoked in any order (including from multiple threads), synchronization may be necessary if the Finalize method may interact with other objects, whether accessible or not. Furthermore, since the order in which Finalize is called is unspecified, implementers of Finalize (or of destructors implemented through overriding Finalize) must take care to correctly handle references to other objects, as their Finalize method may already have been invoked. In general, referenced objects should not be considered valid during finalization. See the System.IDisposable interface for an alternate means of disposing of resources. For C# developers: Destructors are the C# mechanism for performing cleanup operations. Destructors provide appropriate safeguards, such as automatically calling the base type's destructor. In C# code, System.Object.Finalize cannot be called or overridden. |
public virtual System.Int32 GetHashCode() Generates a hash code for the current instance. Returns: A System.Int32 containing the hash code for the current instance. System.Object.GetHashCode serves as a hash function for a specific type. A hash function is used to quickly generate a number (a hash code) corresponding to the value of an object. Hash functions are used with hashtables. A good hash function algorithm rarely generates hash codes that collide. For more information about hash functions, see The Art of Computer Programming , Vol. 3, by Donald E. Knuth. All implementations of System.Object.GetHashCode are required to ensure that for any two object references x and y, if x.Equals(y) == true, then x.GetHashCode() == y.GetHashCode(). Hash codes generated by System.Object.GetHashCode need not be unique. Implementations of System.Object.GetHashCode are not permitted to throw exceptions. The System.Object.GetHashCode implementation attempts to produce a unique hash code for every object, but the hash codes generated by this method are not guaranteed to be unique. Therefore, System.Object.GetHashCode may generate the same hash code for two different instances. It is recommended (but not required) that types overriding System.Object.GetHashCode also override System.Object.Equals(System.Object) . Hashtables cannot be relied on to work correctly if this recommendation is not followed. Use this method to obtain the hash code of an object. Hash codes should not be persisted (i.e. in a database or file) as they are allowed to change from run to run. Example: Example 1 In some cases, System.Object.GetHashCode is implemented to simply return an integer value. The following example illustrates an implementation of System.Int32.GetHashCode , which returns an integer value: using System;
public struct Int32 {
int value;
//other methods...
public override int GetHashCode() {
return value;
}
}
Example 2 Frequently, a type has multiple data members that can participate in generating the hash code. One way to generate a hash code is to combine these fields using an xor (exclusive or) operation, as shown in the following example: using System;
public struct Point {
int x;
int y;
//other methods
public override int GetHashCode() {
return x ^ y;
}
}
Example 3 The following example illustrates another case where the type's fields are combined using xor (exclusive or) to generate the hash code. Notice that in this example, the fields represent user-defined types, each of which implements System.Object.GetHashCode (and should implement System.Object.Equals(System.Object) as well): using System;
public class SomeType {
public override int GetHashCode() {
return 0;
}
}
public class AnotherType {
public override int GetHashCode() {
return 1;
}
}
public class LastType {
public override int GetHashCode() {
return 2;
}
}
public class MyClass {
SomeType a = new SomeType();
AnotherType b = new AnotherType();
LastType c = new LastType();
public override int GetHashCode () {
return a.GetHashCode() ^ b.GetHashCode() ^ c.GetHashCode();
}
}
Avoid implementing System.Object.GetHashCode in a manner that results in circular references. In other words, if AClass.GetHashCode calls BClass.GetHashCode, it should not be the case that BClass.GetHashCode calls AClass.GetHashCode. Example 4 In some cases, the data member of the class in which you are implementing System.Object.GetHashCode is bigger than a System.Int32. In such cases, you could combine the high order bits of the value with the low order bits using an XOR operation, as shown in the following example: using System;
public struct Int64 {
long value;
//other methods...
public override int GetHashCode() {
return ((int)value ^ (int)(value >> 32));
}
}
|
public System.Type GetType() Gets the type of the current instance. Returns: The instance of System.Type that represents the run-time type (the exact type) of the current instance. For two objects x and y that have identical run-time types, System.Object.ReferenceEquals(System.Object,System.Object)(x.GetType(),y.GetType()) returns true . Example: The following example demonstrates the fact that System.Object.GetType returns the run-time type of the current instance: using System;
public class MyBaseClass: Object {
}
public class MyDerivedClass: MyBaseClass {
}
public class Test {
public static void Main() {
MyBaseClass myBase = new MyBaseClass();
MyDerivedClass myDerived = new MyDerivedClass();
object o = myDerived;
MyBaseClass b = myDerived;
Console.WriteLine("mybase: Type is {0}", myBase.GetType());
Console.WriteLine("myDerived: Type is {0}", myDerived.GetType());
Console.WriteLine("object o = myDerived: Type is {0}", o.GetType());
Console.WriteLine("MyBaseClass b = myDerived: Type is {0}", b.GetType());
}
}
The output is mybase: Type is MyBaseClass myDerived: Type is MyDerivedClass object o = myDerived: Type is MyDerivedClass MyBaseClass b = myDerived: Type is MyDerivedClass |
protected System.Object MemberwiseClone() Creates a shallow copy of the current instance. Returns: A shallow copy of the current instance. The run-time type (the exact type) of the returned object is the same as the run-time type of the object that was copied. System.Object.MemberwiseClone creates a new instance of the same type as the current instance and then copies each of the object's non-static fields in a manner that depends on whether the field is a value type or a reference type. If the field is a value type, a bit-by-bit copy of all the field's bits is performed. If the field is a reference type, only the reference is copied. The algorithm for performing a shallow copy is as follows (in pseudo-code): for each instance field f in this instance if (f is a value type) bitwise copy the field if (f is a reference type) copy the reference end for loop This mechanism is referred to as a shallow copy because it copies rather than clones the non-static fields. Because System.Object.MemberwiseClone implements the above algorithm, for any object, a, the following statements are required to be true: System.Object.MemberwiseClone does not call any of the type's constructors. If System.Object.Equals(System.Object) has been overridden, a.MemberwiseClone().Equals(a) might return false . For an alternate copying mechanism, see System.ICloneable . System.Object.MemberwiseClone is protected (rather than public) to ensure that from verifiable code it is only possible to clone objects of the same class as the one performing the operation (or one of its subclasses). Although cloning an object does not directly open security holes, it does allow an object to be created without running any of its constructors. Since these constructors may establish important invariants, objects created by cloning may not have these invariants established, and this may lead to incorrect program behavior. For example, a constructor might add the new object to a linked list of all objects of this class, and cloning the object would not add the new object to that list -- thus operations that relied on the list to locate all instances would fail to notice the cloned object. By making the method protected, only objects of the same class (or a subclass) can produce a clone and implementers of those classes are (presumably) aware of the appropriate invariants and can arrange for them to be true without necessarily calling a constructor. Example: The following example shows a class called MyClass as well as a representation of the instance of MyClass returned by System.Object.MemberwiseClone . using System;
class MyBaseClass {
public static string CompanyName = "My Company";
public int age;
public string name;
}
class MyDerivedClass: MyBaseClass {
static void Main() {
//Create an instance of MyDerivedClass
//and assign values to its fields.
MyDerivedClass m1 = new MyDerivedClass();
m1.age = 42;
m1.name = "Sam";
//Do a shallow copy of m1
//and assign it to m2.
MyDerivedClass m2 = (MyDerivedClass) m1.MemberwiseClone();
}
}
A graphical representation of m1 and m2 might look like this
+---------------+
| 42 | m1
+---------------+
| +---------|-----------------> "Sam"
+---------------+ /|\
|
+---------------+ |
| 42 | | m2
+---------------+ |
| +--------|---------------------|
+---------------+
|
public static System.Boolean ReferenceEquals(System.Object objA, System.Object objB) Determines whether two object references are identical. Parameter objA: First object to compare. Parameter objB: Second object to compare. Returns: True if a and b refer to the same object or are both null references; otherwise, false. This static method provides a way to compare two objects for reference equality. It does not call any user-defined code, including overrides of System.Object.Equals(System.Object) . Example: using System;
class MyClass {
static void Main() {
object o = null;
object p = null;
object q = new Object();
Console.WriteLine(Object.ReferenceEquals(o, p));
p = q;
Console.WriteLine(Object.ReferenceEquals(p, q));
Console.WriteLine(Object.ReferenceEquals(o, p));
}
}
The output is True True False |
public virtual System.String ToString() Creates and returns a System.String representation of the current instance. Returns: A System.String representation of the current instance. System.Object.ToString returns a string whose content is intended to be understood by humans. Where the object contains culture-sensitive data, the string representation returned by System.Object.ToString takes into account the current system culture. For example, for an instance of the System.Double class whose value is zero, the implementation of System.Double.ToString might return "0.00" or "0,00" depending on the current UI culture. Although there are no exact requirements for the format of the returned string, it should as much as possible reflect the value of the object as perceived by the user. System.Object.ToString is equivalent to calling System.Object.GetType to obtain the System.Type object for the current instance and then returning the result of calling the System.Object.ToString implementation for that type. The value returned includes the full name of the type. It is recommended, but not required, that System.Object.ToString be overridden in a derived class to return values that are meaningful for that type. For example, the base data types, such as System.Int32, implement System.Object.ToString so that it returns the string form of the value the object represents. Subclasses that require more control over the formatting of strings than System.Object.ToString provides should implement System.IFormattable, whose System.Object.ToString method uses the culture of the current thread. Example: The following example outputs the textual description of the value of an object of type System.Object to the console. using System;
class MyClass {
static void Main() {
object o = new object();
Console.WriteLine (o.ToString());
}
}
The output is System.Object |
| Functions inherited from System.IComparable: |
|---|
public System.Int32 CompareTo(System.Object obj) Returns the sort order of the current instance compared to the specified object. Parameter obj: The System.Object to compare to the current instance. Returns: A System.Int32 containing a value that reflects the sort order of the current instance as compared to object. The following table defines the conditions under which the returned value is a negative number, zero, or a positive number. For any objects A, B and C, the following are required to be true: A.CompareTo(A) is required to return zero. If A.CompareTo(B) returns zero then B.CompareTo(A) is required to return zero. If A.CompareTo(B) returns zero and B.CompareTo(C) returns zero then A.CompareTo(C) is required to return zero. If A.CompareTo(B) returns a value other than zero then B.CompareTo(A) is required to return a value of the opposite sign. If A.CompareTo(B) returns a value x not equal to zero, and B.CompareTo(C) returns a value y of the same sign as x, then A.CompareTo(C) is required to a value of the same sign as x and y . The exact behavior of this method is unspecified. The intent of this method is to provide a mechanism that orders instances of a class in a manner that is consistent with the mathematical definitions of the relational operators (<, >, and ==), without regard for class-specific definitions of the operators. Use the System.IComparable.CompareTo(System.Object) method to determine the ordering of instances of a class. |
| Functions inherited from System.ICloneable: |
|---|
public System.Object Clone() Creates a copy of the current instance. Returns: A System.Object of the same type as the current instance, containing copies of the non-static members of the current instance. The exact behavior of this method is unspecified. The intent of the method is to provide a mechanism that constructs instances that are copies of the current instance, without regard for class-specific definitions of the term "copy". Use the System.Object.MemberwiseClone method to create a shallow copy of an object. For more information, see System.Object.MemberwiseClone . This method is required to return an instance of the same type as the current instance. Implement this method to provide class-specific copying behavior. Use the System.ICloneable.Clone method to obtain a copy of the current instance. Example: The following example shows an implementation of System.ICloneable.Clone that uses the System.Object.MemberwiseClone method to create a copy of the current instance. using System;
class MyClass :ICloneable {
public int myField;
public MyClass() {
myField = 0;
}
public MyClass(int value) {
myField = value;
}
public object Clone() {
return this.MemberwiseClone();
}
}
public class TestMyClass {
public static void Main() {
MyClass my1 = new MyClass(44);
MyClass my2 = (MyClass) my1.Clone();
Console.WriteLine("my1 {0} my2 {1}",my1.myField, my2.myField);
my2.myField = 22;
Console.WriteLine("my1 {0} my2 {1}",my1.myField, my2.myField);
}
}
The output is my1 44 my2 44 my1 44 my2 22 |
| Functions inherited from System.Collections.IEnumerable: |
|---|
public System.Collections.IEnumerator GetEnumerator() Returns a System.Collections.IEnumerator that can be used for simple iteration over a collection. Returns: A System.Collections.IEnumerator that can be used for simple iteration over a collection. As described above. For a detailed description regarding the use of an enumerator, see System.Collections.IEnumerator. |