Advertisement
7Bpencil

StructTest

Jun 20th, 2021 (edited)
814
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Engine
  4. {
  5.     public struct TestVector
  6.     {
  7.         public float X;
  8.         public float Y;
  9.         public float Z;
  10.  
  11.         public float SumProperty => MathF.Sqrt(X + Y + Z);
  12.  
  13.         public readonly float SumPropertyReadonly => MathF.Sqrt(X + Y + Z);
  14.  
  15.         public float Sum()
  16.         {
  17.             return MathF.Sqrt(X + Y + Z);
  18.         }
  19.  
  20.         public readonly float SumReadonly()
  21.         {
  22.             return MathF.Sqrt(X + Y + Z);
  23.         }
  24.  
  25.         public TestVector(int x, int y, int z)
  26.         {
  27.             X = x;
  28.             Y = y;
  29.             Z = z;
  30.         }
  31.     }
  32.  
  33.  
  34.     public static class TestExtensions
  35.     {
  36.         public static float SumExtension(this in TestVector v)
  37.         {
  38.             return MathF.Sqrt(v.X + v.Y + v.Z);
  39.         }
  40.     }
  41.  
  42.  
  43.     public static class Program
  44.     {
  45.         private static void Main(string[] args)
  46.         {
  47.             var v = new TestVector(1, 2, 3);
  48.             TestSum(v);
  49.             TestSumReadonly(v);
  50.             TestSumExtension(v);
  51.             TestSumProperty(v);
  52.             TestSumPropertyReadonly(v);
  53.         }
  54.  
  55.         public static void TestSum(in TestVector v)
  56.         {
  57.             var sum = v.Sum();
  58.             Console.WriteLine(sum);
  59.         }
  60.  
  61.         public static void TestSumReadonly(in TestVector v)
  62.         {
  63.             var sumReadonly = v.SumReadonly();
  64.             Console.WriteLine(sumReadonly);
  65.         }
  66.  
  67.         public static void TestSumExtension(in TestVector v)
  68.         {
  69.             var sumExt = v.SumExtension();
  70.             Console.WriteLine(sumExt);
  71.         }
  72.  
  73.         public static void TestSumProperty(in TestVector v)
  74.         {
  75.             var sum = v.SumProperty;
  76.             Console.WriteLine(sum);
  77.         }
  78.  
  79.         public static void TestSumPropertyReadonly(in TestVector v)
  80.         {
  81.             var sumReadonly = v.SumPropertyReadonly;
  82.             Console.WriteLine(sumReadonly);
  83.         }
  84.  
  85.     }
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement