using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DemoMoreTypesMembers { // Note, this is a partial class. A partial class can contain partial methods. public partial class SavingsAccount { // Use auto-implemented properties (they have a backing field automatically, and the get/set code is generated by the compiler). public string Name { get; set; } public double Balance { get; set; } // Constructors. public SavingsAccount() { } public SavingsAccount(string name, double balance) { Name = name; Balance = balance; } // A business method. public void Withdraw(double amount) { // Call a partial method (might not actually exist). OnWithdrawing(amount); if (amount > Balance ) amount = Balance; Balance -= amount; // Call another partial method (might not actually exist). OnWithdrawn(amount); } // Partial methods (may, or may not, be implemented in another "partial" part of this class. partial void OnWithdrawing(double amount); partial void OnWithdrawn(double amount); // Return a string representation of account. public override string ToString() { return string.Format("{0}, balance {1:c}", Name, Balance); } } }