-
FundamentalsLogic
Description And even more by removing the foreach bracket, writing System.IComparable instead of writing "using System" at the beggining and removing the useless "public" before the class declaration
Code class Math{public static T Max<T>(params T[]p)where T:System.IComparable<T>{foreach(T a in p)p[0]=p[0].CompareTo(a)<0?a:p[0];return p[0];}}
Test Cases namespace Solution { using NUnit.Framework; [TestFixture] public class SolutionTest { [Test] [TestCase(1,2,2)] [TestCase(2,1,2)] [TestCase(1,1,1)] public void Max_WhenCalled_ReturnTheGreaterArgument(int a, int b, int expectedResult) { var result = Math.Max(a,b); Assert.That(result, Is.EqualTo(expectedResult)); } } }
Output:
-
Code using System;public class Math{public static T Max<T>(params T[]p)where T:IComparable<T>{foreach(T a in p){p[0]=p[0].CompareTo(a)<0?a:p[0];}return p[0];}}- class Math{public static T Max<T>(params T[]p)where T:System.IComparable<T>{foreach(T a in p)p[0]=p[0].CompareTo(a)<0?a:p[0];return p[0];}}
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}