Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 1.14 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. What is the purpose of partial classes?
  2. public partial class MyClass : IDataErrorInfo
  3. {
  4.     partial void ValidateMyProperty(ref string error);
  5.  
  6.     public string this[string propertyName]
  7.     {
  8.         get
  9.         {
  10.             string error = String.Empty;
  11.             if (propertyName == "MyProperty")
  12.                 ValidateMyProperty(ref error);
  13.  
  14.             return error;
  15.         }
  16.     }
  17.  
  18.     public string Error { get { return String.Empty; } }
  19.  
  20.     public int MyProperty { get; set; }
  21. }
  22.        
  23. public partial class MyClass
  24. {
  25.     partial void ValidateMyProperty(ref string error)
  26.     {
  27.         if (MyProperty < 0)
  28.             error = "MyProperty cannot be negative.";
  29.     }
  30. }
  31.        
  32. public partial class testClass {
  33.   private int intMember;
  34.   public string stringMember;
  35. }
  36.        
  37. public partial class testClass {
  38.   private int intAnotherInt;
  39.   public string stringAnotherString;
  40. }
  41.        
  42. public partial class testClass {
  43.   private int intAnotherInt; // Our int from HelloWorld2.cs
  44.   public string stringAnotherString; // Our string from HelloWorld2.cs
  45.   private int intMember; // Our int from HelloWorld.cs
  46.   public string stringMember; // Our string from HelloWorld.cs
  47. }