Add More Constructors To Twodshape – Class Interface

/* C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */// Add more constructors to TwoDShape.   using System;   class TwoDShape { double pri_width; // private double pri_height; // private   // Default constructor. public TwoDShape() { width = height = 0.0; }   // Constructor for TwoDShape. public […]
Continue reading…

Enjoyed this post? Share it!

 
 

Change Field Value In Method – Class Interface

using System;public class Foo { public int i; }   class RefTest2App { public static void ChangeValue(Foo f) { f.i = 42; }static void Main(string[] args) { Foo test = new Foo(); test.i = 6; Console.WriteLine("BEFORE METHOD CALL"); Console.WriteLine("test.i={0}", test.i); Console.WriteLine(); ChangeValue(test); Console.WriteLine("AFTER METHOD CALL"); Console.WriteLine("test.i={0}", test.i); } }
Continue reading…

Enjoyed this post? Share it!

 
 

Illustrates Member Accessibility – Class Interface

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

Enjoyed this post? Share it!

 
 

Interface Demo – Class Interface

/* Learning C# by Jesse LibertyPublisher: O’Reilly ISBN: 0596003765 */ using System; namespace InterfaceDemo { // define the interface interface IStorable { void Read(); void Write(object obj); int Status { get; set; } } // create a Document class that implements the IStorable interface class Document : IStorable { public Document(string s) { Console.WriteLine("Creating document […]
Continue reading…

Enjoyed this post? Share it!

 
 

Overriding Interfaces: Tester Overriding Interfacesas – Class Interface

/* Learning C# by Jesse LibertyPublisher: O’Reilly ISBN: 0596003765 */ using System; namespace OverridingInterfaces { interface IStorable { void Read(); void Write(); } interface ITalk { void Talk(); void Read(); } // Modify Document to also implement ITalk class Document : IStorable, ITalk { // the document constructor public Document(string s) { Console.WriteLine( "Creating document […]
Continue reading…

Enjoyed this post? Share it!

 
 

Structs (Value Types):Structs And Constructors – Class Interface

using System; struct Point { int x; int y;   Point(int x, int y) { this.x = x; this.y = y; } public override string ToString() { return(String.Format("({0}, {1})", x, y)); } } public class StructsandConstructors { public static void Main() { Point[] points = new Point[5]; Console.WriteLine("[2] = {0}", points[2]); } }
Continue reading…

Enjoyed this post? Share it!

 
 

Use Virtual Methods And Polymorphism – Class Interface

/* C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */// Use virtual methods and polymorphism.   using System;   class TwoDShape { double pri_width; // private double pri_height; // private string pri_name; // private   // A default constructor. public TwoDShape() { width = height = 0.0; name = […]
Continue reading…

Enjoyed this post? Share it!

 
 

Constructor Initializers Are Called Bottom-Up But Constructors Are Invoked Top-Down Starting With Constructor In Base Class – Class Interface

using System; public class Starter { public static void Main() { XClass obj = new XClass(); } }public class MyClass { public MyClass(int param) { Console.WriteLine("MyClass constructor"); } }public class YClass : MyClass { public YClass(int param) : base(YClass.MethodA()) { Console.WriteLine("YClass constructor"); } public static int MethodA() { Console.WriteLine("YClass constructor initializer"); return 0; } }public […]
Continue reading…

Enjoyed this post? Share it!

 
 

Demonstrate Readonly – Class Interface

/* C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */// Demonstrate readonly.   using System;   class MyClass { public static readonly int SIZE = 10; }   public class DemoReadOnly { public static void Main() { int[]nums = new int[MyClass.SIZE];   for(int i=0; i<myClass.SIZE; i++) nums[i] = i; […]
Continue reading…

Enjoyed this post? Share it!

 
 

Four Layers Of Class Hierarchy – 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 MyMainClass3 { static void Main(string[] args) { //The function called is based //upon the type called by new. A MyA = new D(); B […]
Continue reading…

Enjoyed this post? Share it!

 
 

Illustrates Use Of Struct – Class Interface

/* Mastering Visual C# .NET by Jason Price, Mike GunderloyPublisher: Sybex; ISBN: 0782129110 *//* Example5_15.cs illustrates the use of a struct */// declare the Rectangle struct struct Rectangle { // declare the fields public int Width; public int Height; // define a constructor public Rectangle(int Width, int Height) { this.Width = Width; this.Height = Height; […]
Continue reading…

Enjoyed this post? Share it!

 
 

Method Overloading Test – Class Interface

/* Learning C# by Jesse LibertyPublisher: O’Reilly ISBN: 0596003765 */ using System; namespace MethodOverloading { public class Time1 { // private member variables private int Year; private int Month; private int Date; private int Hour; private int Minute; private int Second; // public accessor methods public void DisplayCurrentTime() { System.Console.WriteLine("{0}/{1}/{2} {3}:{4}:{5}", Month, Date, Year, Hour, […]
Continue reading…

Enjoyed this post? Share it!

 
 

Properties:Virtual Properties – Class Interface

/* A Programmer’s Introduction to C# (Second Edition) by Eric GunnersonPublisher: Apress L.P. ISBN: 1-893115-62-3 */ // 18 – Properties\Virtual Properties // copyright 2000 Eric Gunnerson using System;public abstract class DrawingObject { public abstract string Name { get; } } class Circle: DrawingObject { string name = "Circle";   public override string Name { get […]
Continue reading…

Enjoyed this post? Share it!

 
 

Super-String Class. – Class Interface

using System;public class MyString { private string fString; public MyString() { fString = ""; } public MyString(string inStr) { fString = inStr; } public string ToStr() { return fString; } public string Right(int nChars) { if (nChars > fString.Length) return fString; string s = ""; for (int i = fString.Length – nChars; i < fString.Length; […]
Continue reading…

Enjoyed this post? Share it!

 
 

Yield Ienumerator – Class Interface

using System; using System.Collections; using System.Collections.Generic; using System.Text;public class Primes { private long min; private long max; public Primes(long minimum, long maximum) { min = minimum; max = maximum; } public IEnumerator GetEnumerator() { for (long possiblePrime = min; possiblePrime <= max; possiblePrime++) { bool isPrime = true; for (long possibleFactor = 2; possibleFactor <= […]
Continue reading…

Enjoyed this post? Share it!