daily pastebin goal
61%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 54 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. How to combine a Partial Class Object in C#?
  2. public class Sample{
  3.     public string name {get;set;}
  4.     public int price {get;set}
  5. }
  6.    
  7. Sample sampleA = new Sample();
  8.  sampleA.name = "test";
  9.  
  10.   Sample sampleB = new Sample();
  11.   sampleB.price = 100;
  12.    
  13. Sample sampleC = sampleA + sampleB;
  14.    
  15. sampleC.name = "test";
  16.   sampleC.price = 100;
  17.    
  18. public static Sample operator +(Sample left, Sample right)
  19.     {
  20.         left.price = right.price;
  21.         return left;
  22.     }
  23.    
  24. public partial class File { public string Prop2 { get;set; } }
  25.    
  26. public partial class File { public int Prop1 { get;set; } }
  27.    
  28. public partial class File
  29. {
  30.      public string Prop2 { get;set; }
  31.      public int Prop1 { get;set; }
  32. }
  33.    
  34. Sample sampleA = new Sample();
  35. sampleA.name = "test";
  36. sampleA.price = 200;
  37.  
  38. Sample sampleB = new Sample();
  39. sampleB.price = 100;
  40.  
  41. Sample sampleC = sampleA + sampleB; // what would be the value of price here: from sampleA or sampleB?
  42.    
  43. public static Sample operator +(Sample sampleA, Sample sampleB){
  44.     return new Sample() { Name = sampleA.Name, Price = sampleB.Price };
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top