Advertisement
T-D-K

Untitled

Nov 28th, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. namespace ConsoleApplication97 {
  5.     class Program {
  6.         static void Main(string[] args) {
  7.             FirstClass firstClass = new FirstClass(100);
  8.             SecondClass secondClass = new SecondClass(100);
  9.             ThirdClass thirdClass = new ThirdClass(100);
  10.             Console.WriteLine(GetPropertyValue(firstClass));
  11.             Console.WriteLine(DoForInterface(firstClass));
  12.             Console.WriteLine(DoForInterface(secondClass));
  13.             Console.WriteLine(DoForInterface(thirdClass));
  14.         }
  15.  
  16.         static int DoForInterface(IInterface iInterface) {
  17.             Stopwatch sw = new Stopwatch();
  18.             sw.Start();
  19.             int sum = 0;
  20.             for (int i = 0; i < 100; i++) {
  21.                 sum += GetPropertyValue(iInterface);
  22.             }
  23.             sw.Stop();
  24.             Console.WriteLine($"Ticks: {sw.Elapsed.Ticks.ToString()}");
  25.             return sum;
  26.         }
  27.  
  28.         static int GetPropertyValue(IInterface iInterface) {
  29.             return iInterface.InterfaceProperty;
  30.         }
  31.     }
  32.  
  33.     public interface IInterface {
  34.         int InterfaceProperty { get; }
  35.     }
  36.  
  37.     public class FirstClass : IInterface {
  38.         public FirstClass(int param) {
  39.             InterfaceProperty = param;
  40.         }
  41.  
  42.         public int InterfaceProperty { get; set; }
  43.     }
  44.  
  45.     public class SecondClass : IInterface {
  46.         public SecondClass(int param) {
  47.             InterfaceProperty = param;
  48.         }
  49.  
  50.         public int InterfaceProperty { get; set; }
  51.     }
  52.  
  53.     public class ThirdClass : IInterface {
  54.         public ThirdClass(int param) {
  55.             InterfaceProperty = param;
  56.         }
  57.  
  58.         public int InterfaceProperty { get; set; }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement