This program creates two Building objects : Class Definition « Language Basics « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » Language Basics » Class DefinitionScreenshots 
This program creates two Building objects
This program creates two Building objects

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// This program creates two Building objects. 
 
  
using System;  
  
class Building {   
  public int floors;    // number of floors 
  public int area;      // total square footage of building 
  public int occupants; // number of occupants 
}   
   
// This class declares two objects of type Building.   
public class BuildingDemo1 {   
  public static void Main() {   
    Building house = new Building();   
    Building office = new Building()
 
    int areaPP; // area per person 
   
    // assign values to fields in house 
    house.occupants = 4;  
    house.area = 2500;  
    house.floors = 2;  
 
    // assign values to fields in office 
    office.occupants = 25;  
    office.area = 4200;  
    office.floors = 3;  
   
    // compute the area per person in house 
    areaPP = house.area / house.occupants;  
   
    Console.WriteLine("house has:\n  " 
                      house.floors + " floors\n  " 
                      house.occupants + " occupants\n  " 
                      house.area + " total area\n  " 
                      areaPP + " area per person")
 
    Console.WriteLine()
 
    // compute the area per person in office 
    areaPP = office.area / office.occupants;  
 
    Console.WriteLine("office has:\n  " 
                      office.floors + " floors\n  " 
                      office.occupants + " occupants\n  " 
                      office.area + " total area\n  " 
                      areaPP + " area per person")
  }   


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