Program That Uses Building Class – Class Interface

/* C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */ // A program that uses the Building class.   using System;   class Building { public int floors; // number of floors public int area; // total square footage of building public int occupants; // number of occupants } […]
Continue reading…

Enjoyed this post? Share it!

 
 

Class Hierarchy: Override And Virtual – Class Interface

/* * C# Programmers Pocket Consultant * Author: Gregory S. MacBeth * Email: gmacbeth@comporium.net * Create Date: June 27, 2003 * Last Modified Date: */ using System;namespace Client.Chapter_5___Building_Your_Own_Classes { public class MyMainClass13 { static void Main(string[] args) { //The function called is based //upon the type called by new. B MyB = new C(); MyB.Display(); […]
Continue reading…

Enjoyed this post? Share it!

 
 

Demonstrate Virtual Method – Class Interface

/* C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */// Demonstrate a virtual method.   using System;   class Base { // Create virtual method in the base class. public virtual void who() { Console.WriteLine("who() in Base"); } }   class Derived1 : Base { // Override who() in […]
Continue reading…

Enjoyed this post? Share it!

 
 

Extends Ienumerable – Class Interface

using System; using System.Collections.Generic; using System.Text;using System.Collections;public class Employee { public int currAge; public string fName, lName; public Employee() { } public Employee(string firstName, string lastName, int age) { currAge = age; fName = firstName; lName = lastName; } public override string ToString() { return string.Format("{0}, {1} is {2} years old", lName, fName, currAge); } […]
Continue reading…

Enjoyed this post? Share it!

 
 

Illustrates Polymorphism – Class Interface

/* Mastering Visual C# .NET by Jason Price, Mike GunderloyPublisher: Sybex; ISBN: 0782129110 */ /* Example7_2.cs illustrates polymorphism */using System;// declare the MotorVehicle class class MotorVehicle { // declare the fields public string make; public string model; // define a constructor public MotorVehicle(string make, string model) { this.make = make; this.model = model; } // […]
Continue reading…

Enjoyed this post? Share it!

 
 

Iterates Collection Forward And Reverse – Class Interface

using System; using System.Collections.Generic; public class Starter { public static void Main() { Console.WriteLine("Forward List"); MyClass obj = new MyClass(); foreach (int item in obj) { Console.Write(item); } Console.WriteLine("\nReverse List"); foreach (int item in obj.Reverse) { Console.Write(item); } } }public class MyClass { private int[] list1 = new int[] { 0, 2, 4, 6, 8 […]
Continue reading…

Enjoyed this post? Share it!

 
 

Private Field And Public Property In Inheritance – Class Interface

/* C# Programming Tips & Techniques by Charles Wright, Kris JamsaPublisher: Osborne/McGraw-Hill (December 28, 2001) ISBN: 0072193794 */namespace nsInherit { using System;   public class clsMainInherit { static public void Main () { clsDerived derived = new clsDerived(); derived.Property = 42; derived.ShowField(); } } // // Define a base class with a private field and […]
Continue reading…

Enjoyed this post? Share it!

 
 

Constructor Initializes Internal Object. Dispose Method Closes File Resource. Destructor Delegates To Dispose Method. – Class Interface

using System; using System.IO;public class WriteToFile : IDisposable { public WriteToFile(string _file, string _text) { file = new StreamWriter(_file, true); text = _text; } public void WriteText() { file.WriteLine(text); } public void Dispose() { file.Close(); } ~WriteToFile() { Dispose(); } private StreamWriter file; private string text; }public class Writer { public static void Main() { […]
Continue reading…

Enjoyed this post? Share it!

 
 

Two-Dimensional Fail-Soft Array – Class Interface

/* C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */// A two-dimensional fail-soft array.   using System;   class FailSoftArray2D { int[,] a; // reference to underlying 2D array int rows, cols; // dimensions public int Length; // Length is public   public bool errflag; // indicates outcome of […]
Continue reading…

Enjoyed this post? Share it!

 
 

Copy Struct – Class Interface

/* C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */ // Copy a struct.   using System;   // Define a structure. struct MyStruct { public int x; }   // Demonstrate structure assignment. public class StructAssignment { public static void Main() { MyStruct a; MyStruct b;   a.x […]
Continue reading…

Enjoyed this post? Share it!

 
 

Demonstrates Overriding Tostring() Method To Provide Custom String Output – Class Interface

/* C# Programming Tips & Techniques by Charles Wright, Kris JamsaPublisher: Osborne/McGraw-Hill (December 28, 2001) ISBN: 0072193794 */ // tm1.cs – demonstrates overriding the ToString() method to provide a custom // string output. // // Compile this program using the following command line: // D:>csc tm1.cs // namespace nsStructure { using System; using System.Globalization; public […]
Continue reading…

Enjoyed this post? Share it!

 
 

Illustrates Explicit Interface Member Implementation – Class Interface

/* Mastering Visual C# .NET by Jason Price, Mike GunderloyPublisher: Sybex; ISBN: 0782129110 *//* Example8_7.cs illustrates an explicit interface member implementation */using System;// define the IDrivable interface public interface IDrivable { void TurnLeft(); }// define the ISteerable interface public interface ISteerable { void TurnLeft(); }// Car class implements the IMovable interface class Car : IDrivable, […]
Continue reading…

Enjoyed this post? Share it!

 
 

Implement Icomparer – Class Interface

using System; using System.Collections;class Album : IComparable, ICloneable { private string _Title; private string _Artist; public Album(string artist, string title) { _Artist = artist; _Title = title; } public string Title { get { return _Title; } set { _Title = value; } } public string Artist { get { return _Artist; } set { […]
Continue reading…

Enjoyed this post? Share it!

 
 

Object Assignment – Class Interface

using System; public class Foo { public int i; }   class RefTest1App { static void Main(string[] args) { Foo test1 = new Foo(); test1.i = 1; Foo test2 = new Foo(); test2.i = 2; Console.WriteLine("BEFORE OBJECT ASSIGNMENT"); Console.WriteLine("test1.i={0}", test1.i); Console.WriteLine("test2.i={0}", test2.i); Console.WriteLine(); test1 = test2; Console.WriteLine("AFTER OBJECT ASSIGNMENT"); Console.WriteLine("test1.i={0}", test1.i); Console.WriteLine("test2.i={0}", test2.i); Console.WriteLine(); test1.i […]
Continue reading…

Enjoyed this post? Share it!

 
 

Return Array – Class Interface

/* C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */// Return an array.   using System;   class Factor { /* Return an array containing the factors of num. On return, numfactors will contain the number of factors found. */ public int[] findfactors(int num, out int numfactors) { int[] […]
Continue reading…

Enjoyed this post? Share it!

 
 

Tree Enumerator – Class Interface

using System; using System.Collections.Generic; using System.Linq; using System.Text;public class Tree<titem> : IEnumerable<titem> where TItem : IComparable<titem> { public Tree(TItem nodeValue) { this.NodeData = nodeValue; this.LeftTree = null; this.RightTree = null; } public void Insert(TItem newItem) { TItem currentNodeValue = this.NodeData; if (currentNodeValue.CompareTo(newItem) > 0) { if (this.LeftTree == null) { this.LeftTree = new Tree<titem>(newItem); } […]
Continue reading…

Enjoyed this post? Share it!

 
 

Add Method To Building – Class Interface

/* C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */ // Add a method to Building.   using System;   class Building { public int floors; // number of floors public int area; // total square footage of building public int occupants; // number of occupants   // Display […]
Continue reading…

Enjoyed this post? Share it!

 
 

Casting Objects: Upcast – Class Interface

using System;   public class CPU { public string model;   public CPU(string model) { this.model = model; }   public void Start() { Console.WriteLine(model + " started"); } }   public class Intel : CPU { public bool convertible;   public Intel(string model, bool convertible) : base(model) { this.convertible = convertible; } }   […]
Continue reading…

Enjoyed this post? Share it!

 
 

Define Indexer – Class Interface

/* Learning C# by Jesse LibertyPublisher: O’Reilly ISBN: 0596003765 */ using System; namespace Indexers { // a simplified ListBox control class ListBoxTest { private string[] strings; private int ctr = 0; // initialize the listbox with strings public ListBoxTest(params string[] initialStrings) { // allocate space for the strings strings = new String[256]; // copy the […]
Continue reading…

Enjoyed this post? Share it!