|
Il presente articolo è stato tradotto automaticamente. Passare il puntatore sulle frasi nell'articolo per visualizzare il testo originale. Ulteriori informazioni.
|
Traduzione
Originale
|
Classe Object
Spazio dei nomi: System
Assembly: mscorlib (in mscorlib.dll)
Il tipo Object espone i seguenti membri.
| Nome | Descrizione | |
|---|---|---|
![]() ![]() ![]() ![]() | Equals(Object) | |
![]() ![]() ![]() ![]() ![]() | Equals(Object, Object) | |
![]() ![]() ![]() ![]() | Finalize | |
![]() ![]() ![]() ![]() | GetHashCode | |
![]() ![]() ![]() ![]() | GetType | |
![]() ![]() ![]() ![]() | MemberwiseClone | |
![]() ![]() ![]() ![]() ![]() | ReferenceEquals | |
![]() ![]() ![]() ![]() | ToString |
Equals - consente il confronto tra oggetti. Finalize - esegue operazioni di pulizia prima che un oggetto venga recuperato automaticamente. GetHashCode - genera un numero corrispondente al valore dell'oggetto con il quale supportare la tabella hash. ToString - produce una stringa di testo in formato leggibile che descrive un'istanza della classe.
Considerazioni sulle prestazioni
Creare un metodo generico che accetta un tipo Object e un set di overload di metodi specifici che accettano ogni tipo di valore che prevede la classe per gestire frequentemente. Se esiste un metodo specifico per il tipo che accetta il tipo di parametro della chiamata, non si verifica il boxing e viene richiamato il metodo specifico per il tipo. Se non esiste un argomento del metodo che corrisponde al tipo di parametro della chiamata, viene eseguito il boxing del parametro e viene invocato il metodo generale. Progettare il tipo e i relativi membri per utilizzare i generics. In Common Language Runtime, quando si crea un'istanza della classe e si specifica un argomento di tipo generico, viene creato un tipo generico chiuso. Il metodo generico è specifico per il tipo e può essere richiamato senza procedere al boxing del parametro della chiamata.
using System; // The Point class is derived from System.Object. class Point { public int x, y; public Point(int x, int y) { this.x = x; this.y = y; } public override bool Equals(object obj) { // If this and obj do not refer to the same type, then they are not equal. if (obj.GetType() != this.GetType()) return false; // Return true if x and y fields match. Point other = (Point) obj; return (this.x == other.x) && (this.y == other.y); } // Return the XOR of the x and y fields. public override int GetHashCode() { return x ^ y; } // Return the point's value as a string. public override String ToString() { return String.Format("({0}, {1})", x, y); } // Return a copy of this point object by making a simple field copy. public Point Copy() { return (Point) this.MemberwiseClone(); } } public sealed class App { static void Main() { // Construct a Point object. Point p1 = new Point(1,2); // Make another Point object that is a copy of the first. Point p2 = p1.Copy(); // Make another variable that references the first Point object. Point p3 = p1; // The line below displays false because p1 and p2 refer to two different objects. Console.WriteLine(Object.ReferenceEquals(p1, p2)); // The line below displays true because p1 and p2 refer to two different objects that have the same value. Console.WriteLine(Object.Equals(p1, p2)); // The line below displays true because p1 and p3 refer to one object. Console.WriteLine(Object.ReferenceEquals(p1, p3)); // The line below displays: p1's value is: (1, 2) Console.WriteLine("p1's value is: {0}", p1.ToString()); } } // This code example produces the following output: // // False // True // True // p1's value is: (1, 2) //
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (ruoli di base del server non supportati), Windows Server 2008 R2 (ruoli di base del server supportati con SP1 o versione successiva, Itanium non supportato)
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.


