public static void Input<T>(T[] nums) where T : IParsable<T>
isWorkThat = true;
добавить return;
, а содержимое else блока перенести в конец функции после всех if. требуется подсвечивать текущий элемент
с помощью события нажания
<MultiBinding Converter="{StaticResource IsEqualsConverter}">
<Binding />
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type ToolBar}}" Path="DataContext.CurrentElement" />
</MultiBinding>
{RelativeSource Mode=PreviousData}
- у первого элемента он будет {x:Null}
Background="Transparent"
(прозрачный цвет считается за фон, но визуально ничего не меняет), то всё будет работать.IEqualityComparer<T>
используется в коде с обобщениями (generics).IEqualityComparer<T>
, то при сравнении ключей-структур постоянно бы происходил боксинг, что не очень эффективно. (У простых структур всё-равно будет боксинг, чтобы его не было надо реализовать IEquatable).IEqualityComparer<T>
мало, есть более лаконичные вариант для Equals и GetHashCode. Почему это поле не передается через, передается null
CommandParameter="{Binding ElementName=selfUserControl,Path=Points, Mode=OneWay}">, selfUserControl x:Name элемента.
Находил примеры, там везде свойство ItemsSource, но такого свойства нету у Canvas
// [][] 4865 // [,] 5192 // [] 4852
string n2string = "sdfihsdfguhdsfo[ghdfhgdsfhghdfsgdfhghdsfg9wh328932u82hbsab zb cx9832u83232hbnibcz";
int countMinus3 = n2string.Length - 3;
{
string lastThreeSymbols = n2string.Substring(countMinus3);
Console.WriteLine($"lastThreeSymbols = {lastThreeSymbols}");
}
{
string lastThreeSymbols = string.Concat(n2string.Where((_, i) => i >= countMinus3));
Console.WriteLine($"lastThreeSymbols = {lastThreeSymbols}");
}
{
string lastThreeSymbols = n2string.Where((_, i) => i >= countMinus3).Aggregate(string.Empty, (s, c) => s + c);
Console.WriteLine($"lastThreeSymbols = {lastThreeSymbols}");
}
{
string lastThreeSymbols = n2string.Aggregate(string.Empty, (s, c) => (s.Length > 2 ? s.Substring(1) : s) + c);
Console.WriteLine($"lastThreeSymbols = {lastThreeSymbols}");
}
var someItems = _someService.GetList();
foreach (var item in someItems) // item внутри не используется, можно убрать этот foreach
{
var additionalItems = _additionItemsSerivce.GetList();
foreach (var additionalItem in additionalItems)
{
var properties = additionalItem.Properties;
foreach (var property in properties)
{
property.First = true;
property.First = true; // зачем делать одно и тоже два раза?
_additionItemsSerivce.UpdateProperies(additionalItem); // property не используется, значит можно вынести за этот foreach
}
}
}
var additionalItems = _additionItemsSerivce.GetList();
foreach (var additionalItem in additionalItems)
{
var properties = additionalItem.Properties;
foreach (var property in properties)
property.First = true;
_additionItemsSerivce.UpdateProperies(additionalItem);
}
$"..."
- синтаксический сахар для get_node("...").private Node node;
public override void _Ready()
{
node = GetNode<Node>("../Node");
}
public static FileStream OpenRead(string path)
{
return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
}
internal const FileShare DefaultShare = FileShare.Read;
public FileStream(string path, FileMode mode)
: this(path, mode, mode == FileMode.Append ? FileAccess.Write : FileAccess.ReadWrite, DefaultShare, DefaultBufferSize, DefaultIsAsync) {}
ReadOnlySpan<byte>
можно распарсить число при помощи System.Buffers.Text.Utf8Parser.TryParse
var (a, b) = Console.ReadLine().Split(" ").Select(int.Parse);
public static class DeconstructEnumerable
{
public static void Deconstruct<T>(this System.Collections.Generic.IEnumerable<T> enumerable, out T item1, out T item2)
{
using var enumerator = enumerable.GetEnumerator();
if (!enumerator.MoveNext())
throw new ArgumentException("not enough values to unpack (expected 2, got 0)", nameof(enumerable));
item1 = enumerator.Current;
if (!enumerator.MoveNext())
throw new ArgumentException("not enough values to unpack (expected 2, got 1)", nameof(enumerable));
item2 = enumerator.Current;
if (enumerator.MoveNext())
throw new ArgumentException("too many values to unpack (expected 2)", nameof(enumerable));
}
}
(int, char, char) FindFirstDifference(string a, string b)
{
var length = Math.Min(a.Length, b.Length);
for (int i = 0; i < length; i++)
{
if (a[i] != b[i])
return (i, a[i], b[i]);
}
if (a.Length == b.Length)
return (-1, '\0', '\0');
return (length, a.Length == length ? '\0' : a[length], b.Length == length ? '\0' : b[length]);
}