Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All Projects updated to .NET 6, redundant code removed and old syntax… #167

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Algorithms/Algorithms.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
114 changes: 56 additions & 58 deletions Algorithms/Common/Comparers.cs
Original file line number Diff line number Diff line change
@@ -1,70 +1,68 @@
using System;

namespace Algorithms.Common
namespace Algorithms.Common;

public static class Comparers
{
public static class Comparers
/// <summary>
/// Determines if a specific value is a number.
/// </summary>
/// <returns><c>true</c> if the value is a number; otherwise, <c>false</c>.</returns>
/// <param name="value">Value.</param>
/// <typeparam name="T">The Type of value.</typeparam>
public static bool IsNumber<T>(this T value)
{
/// <summary>
/// Determines if a specific value is a number.
/// </summary>
/// <returns><c>true</c> if the value is a number; otherwise, <c>false</c>.</returns>
/// <param name="value">Value.</param>
/// <typeparam name="T">The Type of value.</typeparam>
public static bool IsNumber<T>(this T value)
{
if (value is sbyte) return true;
if (value is byte) return true;
if (value is short) return true;
if (value is ushort) return true;
if (value is int) return true;
if (value is uint) return true;
if (value is long) return true;
if (value is ulong) return true;
if (value is float) return true;
if (value is double) return true;
if (value is decimal) return true;
return false;
}

if (value is sbyte) return true;
if (value is byte) return true;
if (value is short) return true;
if (value is ushort) return true;
if (value is int) return true;
if (value is uint) return true;
if (value is long) return true;
if (value is ulong) return true;
if (value is float) return true;
if (value is double) return true;
if (value is decimal) return true;
return false;
}

/// <summary>
/// Determines if firstValue is equals to the specified secondValue.
/// </summary>
/// <returns><c>true</c> if firstValue is equals to the specified secondValue; otherwise, <c>false</c>.</returns>
/// <param name="firstValue">The first value.</param>
/// <param name="secondValue">The second value.</param>
/// <typeparam name="T">The Type of values.</typeparam>
public static bool IsEqualTo<T>(this T firstValue, T secondValue) where T : IComparable<T>
{
return firstValue.Equals(secondValue);
}

/// <summary>
/// Determines if firstValue is equals to the specified secondValue.
/// </summary>
/// <returns><c>true</c> if firstValue is equals to the specified secondValue; otherwise, <c>false</c>.</returns>
/// <param name="firstValue">The first value.</param>
/// <param name="secondValue">The second value.</param>
/// <typeparam name="T">The Type of values.</typeparam>
public static bool IsEqualTo<T>(this T firstValue, T secondValue) where T : IComparable<T>
{
return firstValue.Equals(secondValue);
}

/// <summary>
/// Determines if thisValue is greater than the specified otherValue.
/// </summary>
/// <returns><c>true</c> if thisValue is greater than the specified otherValue; otherwise, <c>false</c>.</returns>
/// <param name="firstValue">The first value.</param>
/// <param name="secondValue">The second value.</param>
/// <typeparam name="T">The Type of values.</typeparam>
public static bool IsGreaterThan<T>(this T firstValue, T secondValue) where T : IComparable<T>
{
return firstValue.CompareTo(secondValue) > 0;
}

/// <summary>
/// Determines if thisValue is greater than the specified otherValue.
/// </summary>
/// <returns><c>true</c> if thisValue is greater than the specified otherValue; otherwise, <c>false</c>.</returns>
/// <param name="firstValue">The first value.</param>
/// <param name="secondValue">The second value.</param>
/// <typeparam name="T">The Type of values.</typeparam>
public static bool IsGreaterThan<T>(this T firstValue, T secondValue) where T : IComparable<T>
{
return firstValue.CompareTo(secondValue) > 0;
}

/// <summary>
/// Determines if thisValue is less than the specified otherValue.
/// </summary>
/// <returns><c>true</c> if thisValue is less than the specified otherValue; otherwise, <c>false</c>.</returns>
/// <param name="firstValue">The first value.</param>
/// <param name="secondValue">The second value.</param>
/// <typeparam name="T">The Type of values.</typeparam>
public static bool IsLessThan<T>(this T firstValue, T secondValue) where T : IComparable<T>
{
return firstValue.CompareTo(secondValue) < 0;
}

/// <summary>
/// Determines if thisValue is less than the specified otherValue.
/// </summary>
/// <returns><c>true</c> if thisValue is less than the specified otherValue; otherwise, <c>false</c>.</returns>
/// <param name="firstValue">The first value.</param>
/// <param name="secondValue">The second value.</param>
/// <typeparam name="T">The Type of values.</typeparam>
public static bool IsLessThan<T>(this T firstValue, T secondValue) where T : IComparable<T>
{
return firstValue.CompareTo(secondValue) < 0;
}

}
}
72 changes: 35 additions & 37 deletions Algorithms/Common/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
using System.Collections.Generic;
using DataStructures.Lists;

namespace Algorithms.Common
namespace Algorithms.Common;

public static class Helpers
{
public static class Helpers
/// <summary>
/// Swaps two values in an IList<T> collection given their indexes.
/// </summary>
public static void Swap<T>(this IList<T> list, int firstIndex, int secondIndex)
{
/// <summary>
/// Swaps two values in an IList<T> collection given their indexes.
/// </summary>
public static void Swap<T>(this IList<T> list, int firstIndex, int secondIndex)
{
if (list.Count < 2 || firstIndex == secondIndex) //This check is not required but Partition function may make many calls so its for perf reason
return;
if (list.Count < 2 || firstIndex == secondIndex) //This check is not required but Partition function may make many calls so its for perf reason
return;

var temp = list[firstIndex];
list[firstIndex] = list[secondIndex];
list[secondIndex] = temp;
}
var temp = list[firstIndex];
list[firstIndex] = list[secondIndex];
list[secondIndex] = temp;
}

/// <summary>
/// Swaps two values in an ArrayList<T> collection given their indexes.
/// </summary>
public static void Swap<T>(this ArrayList<T> list, int firstIndex, int secondIndex)
{
if (list.Count < 2 || firstIndex == secondIndex) //This check is not required but Partition function may make many calls so its for perf reason
return;
/// <summary>
/// Swaps two values in an ArrayList<T> collection given their indexes.
/// </summary>
public static void Swap<T>(this ArrayList<T> list, int firstIndex, int secondIndex)
{
if (list.Count < 2 || firstIndex == secondIndex) //This check is not required but Partition function may make many calls so its for perf reason
return;

var temp = list[firstIndex];
list[firstIndex] = list[secondIndex];
list[secondIndex] = temp;
}
var temp = list[firstIndex];
list[firstIndex] = list[secondIndex];
list[secondIndex] = temp;
}

/// <summary>
/// Populates a collection with a specific value.
/// </summary>
public static void Populate<T>(this IList<T> collection, T value)
{
if (collection == null)
return;
/// <summary>
/// Populates a collection with a specific value.
/// </summary>
public static void Populate<T>(this IList<T> collection, T value)
{
if (collection == null)
return;

for (int i = 0; i < collection.Count; i++)
{
collection[i] = value;
}
for (int i = 0; i < collection.Count; i++)
{
collection[i] = value;
}
}
}

}
Loading