Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Engine
- {
- public struct TestVector
- {
- public float X;
- public float Y;
- public float Z;
- public float SumProperty => MathF.Sqrt(X + Y + Z);
- public readonly float SumPropertyReadonly => MathF.Sqrt(X + Y + Z);
- public float Sum()
- {
- return MathF.Sqrt(X + Y + Z);
- }
- public readonly float SumReadonly()
- {
- return MathF.Sqrt(X + Y + Z);
- }
- public TestVector(int x, int y, int z)
- {
- X = x;
- Y = y;
- Z = z;
- }
- }
- public static class TestExtensions
- {
- public static float SumExtension(this in TestVector v)
- {
- return MathF.Sqrt(v.X + v.Y + v.Z);
- }
- }
- public static class Program
- {
- private static void Main(string[] args)
- {
- var v = new TestVector(1, 2, 3);
- TestSum(v);
- TestSumReadonly(v);
- TestSumExtension(v);
- TestSumProperty(v);
- TestSumPropertyReadonly(v);
- }
- public static void TestSum(in TestVector v)
- {
- var sum = v.Sum();
- Console.WriteLine(sum);
- }
- public static void TestSumReadonly(in TestVector v)
- {
- var sumReadonly = v.SumReadonly();
- Console.WriteLine(sumReadonly);
- }
- public static void TestSumExtension(in TestVector v)
- {
- var sumExt = v.SumExtension();
- Console.WriteLine(sumExt);
- }
- public static void TestSumProperty(in TestVector v)
- {
- var sum = v.SumProperty;
- Console.WriteLine(sum);
- }
- public static void TestSumPropertyReadonly(in TestVector v)
- {
- var sumReadonly = v.SumPropertyReadonly;
- Console.WriteLine(sumReadonly);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement