Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- namespace ConsoleApplication97 {
- class Program {
- static void Main(string[] args) {
- FirstClass firstClass = new FirstClass(100);
- SecondClass secondClass = new SecondClass(100);
- ThirdClass thirdClass = new ThirdClass(100);
- Console.WriteLine(GetPropertyValue(firstClass));
- Console.WriteLine(DoForInterface(firstClass));
- Console.WriteLine(DoForInterface(secondClass));
- Console.WriteLine(DoForInterface(thirdClass));
- }
- static int DoForInterface(IInterface iInterface) {
- Stopwatch sw = new Stopwatch();
- sw.Start();
- int sum = 0;
- for (int i = 0; i < 100; i++) {
- sum += GetPropertyValue(iInterface);
- }
- sw.Stop();
- Console.WriteLine($"Ticks: {sw.Elapsed.Ticks.ToString()}");
- return sum;
- }
- static int GetPropertyValue(IInterface iInterface) {
- return iInterface.InterfaceProperty;
- }
- }
- public interface IInterface {
- int InterfaceProperty { get; }
- }
- public class FirstClass : IInterface {
- public FirstClass(int param) {
- InterfaceProperty = param;
- }
- public int InterfaceProperty { get; set; }
- }
- public class SecondClass : IInterface {
- public SecondClass(int param) {
- InterfaceProperty = param;
- }
- public int InterfaceProperty { get; set; }
- }
- public class ThirdClass : IInterface {
- public ThirdClass(int param) {
- InterfaceProperty = param;
- }
- public int InterfaceProperty { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement