A simple inventory example : Class Definition « Class Interface « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Class Interface » Class DefinitionScreenshots 
A simple inventory example
A simple inventory example

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/

// A simple inventory example. 
 
using System; 
using System.Collections; 
 
class Inventory 
  string name; 
  double cost; 
  int onhand; 
 
  public Inventory(string n, double c, int h) { 
    name = n; 
    cost = c; 
    onhand = h; 
  
 
  public override string ToString() { 
    return 
      String.Format("{0,-10}Cost: {1,6:C}  On hand: {2}"
                    name, cost, onhand)
  

 
public class InventoryList 
  public static void Main() { 
    ArrayList inv = new ArrayList()
     
    // Add elements to the list 
    inv.Add(new Inventory("Pliers"5.953))
    inv.Add(new Inventory("Wrenches"8.292));    
    inv.Add(new Inventory("Hammers"3.504))
    inv.Add(new Inventory("Drills"19.888))
 
    Console.WriteLine("Inventory list:")
    foreach(Inventory i in inv) { 
      Console.WriteLine("   " + i)
    
  
}


           
       
Related examples in the same category
1.simulate a bank account
2.Using Initializers
3.Declaring and Defining Classes
4.Declaring Class Instances
5.Assign value to classAssign value to class
6.Declare class and use itDeclare class and use it
7.Illustrates how to declare classes, object references, and create objectsIllustrates how to declare classes, object references, and create objects
8.Illustrates how to assign default values to fields using initializersIllustrates how to assign default values to fields using initializers
9.illustrates how to use a 'has a' relationshipillustrates how to use a 'has a' relationship
10.Illustrates nested classesIllustrates nested classes
11.Multiple constructors in a class definitionMultiple constructors in a class definition
12.Demonstrate the use of a nested class to contain dataDemonstrate the use of a nested class to contain data
13.Show name hiding in a derived classShow name hiding in a derived class
14.Illustrates hidingIllustrates hiding
15.Variable in and out a classVariable in and out a class
16.Create classCreate class
17.A program that uses the Building classA program that uses the Building class
18.This program creates two Building objectsThis program creates two Building objects
19.Return an objectReturn an object
20.Uses a class from Example16_3a.cs
21.A Simple C# ClassA Simple C# Class
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.