Skip to Content
C# 3.0: kurz & gut
book

C# 3.0: kurz & gut

by Joseph Albahari, Ben Albahari
May 2008
Intermediate to advanced content levelIntermediate to advanced
248 pages
3h 50m
German
O'Reilly Verlag
Content preview from C# 3.0: kurz & gut

Der Typ object

object (System.Object) ist die Ausgangsbasisklasse für alle Typen. Jeder Typ kann per Upcast in ein object umgewandelt werden.

Um zu zeigen, wie das nützlich sein kann, stellen Sie sich einen allgemeinen Stack vor. Ein Stack ist eine Datenstruktur, die auf dem LIFO-Prinzip – »Last in, First out« – basiert. Ein Stack hat zwei Operationen: per Push ein Objekt auf den Stack schieben und eines per Pop wieder herunterholen. So sieht eine einfache Implementierung aus, die bis zu zehn Objekte verwalten kann:

public class Stack
{
  int position;
  object[] data = new object[10];

  public void Push (object obj)
    { data[position++] = obj;  }

  public object Pop(  )
   { return data[--position]; }
}

Da Stack mit dem Typ object arbeitet, können wir Instanzen ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

How I Built a Personal Board of Directors With GenAI

How I Built a Personal Board of Directors With GenAI

Vipin Gupta
How to Become a Game-Changing Leader

How to Become a Game-Changing Leader

Douglas A. Ready, Alan Mulally
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer

Publisher Resources

ISBN: 9783897215443