All Questions
78
questions
0
votes
2
answers
611
views
how to await until parallel task done
I'm new with C#. I'm writing window form for sorting files inside folder according to it extension.
It's work when do the task with one folder but I modified it to do it from multiple item in listbox.
...
4
votes
1
answer
344
views
Overriding a method with a ref struct param in older C# versions
I'm trying to override a JsonConverter<T> in the System.Text.Json package which has an abstract Read method which can be ovveridden as:
public override object Read(ref Utf8JsonReader reader, ...
4
votes
1
answer
386
views
If I have a c# readonly struct that has non readonly structs as members, will compiler create defensive copy with in parameter
so, if I have for example a struct PlayerData that has members of Vector3 structs defined in System.Numerics (not readonly structs)
public readonly struct PlayerData
{
public readonly Vector3 ...
2
votes
1
answer
692
views
Yield keyword can not be used in ref struct?
I would like to use yield in ref structure method:
public ref struct RefStruct
{
public IEnumerator<int> GetEnumerator()
{
yield return 1;
}
}
The compiler complains about ...
6
votes
1
answer
1k
views
What is the best practice to implement equality for readonly structs? [closed]
I've just started to program in C# last year and I'm still learning the language. I have a question regarding readonly struct type and equality comparison methods.
When creating a struct in C#, I know ...
2
votes
1
answer
542
views
Are mutable structs copied when passed through methods via in parameters?
I want to minimize copying of structs in a maths library and read about the C# 7.2 in modifier, especially the warnings when using it with mutable structs.
It so happens that I have this mutable ...
4
votes
0
answers
863
views
Is there a way to use the ReadOnlySpan<char> overloads for StringBuilder and TryParse methods in a netstandard2.0 class library?
I have a NetStandard2.0 class library. I have imported the System.Memory nuget package, which means I can use Span<T> inside it. That's well and good, but the nuget package doesn't seem to ...
7
votes
3
answers
994
views
What is the difference between "this ref" and "ref this" when talking about C# 7.2 ref extension methods?
Consider the following extension methods:
public static void Toggle(this ref bool @bool) => @bool = !@bool;
public static void Toggle2(ref this bool @bool) => @bool = !@bool;
These simply ...
4
votes
1
answer
583
views
C#. Ref returning delegate for ref extension method
I have the following extension method for monitoring a variable and awaiting until it has a given expected value:
public static async Task AwaitForValue<T>(this Func<T> ...
6
votes
1
answer
602
views
Why is this method invocation ambiguous?
Why does the first call to Foo below compile but the second one results in an ambiguous invocation compiler error?
(using c# 7.2)
private static void AmbiguousAsyncOverload() {
Foo(() =>...
4
votes
2
answers
189
views
Using the is operator with unconstrained generics
C# Version: 7.2
My Ms Build version: Unknown (if anyone can tell me how to find it on my machine please do)
My Version of Visual Studio: Visual Studio Professional 2019
I'm going to boil this down ...
3
votes
0
answers
565
views
Using readonly structs as Dictionary Key
I was wondering how readonly structs behave when used a key in a Dictionary. I'm aware the combition of readonly and 'in' is to prevent copies of large structs being made unnecessarily and that the ...
2
votes
1
answer
994
views
Is there a way to compare 2 ref structs by reference?
Recently I was wandering if it's possible to compare structs by reference. As reading a struct variable creates a copy of that variable, comparing standard structs by reference seems impossible. ...
4
votes
1
answer
2k
views
Copy/set a single byte in a Memory<byte>
I'm starting out with System.Buffers.MemoryPool<T> and System.Memory<T> in C#, looking to reduce allocations for byte arrays.
I have a bunch of bytes and byte arrays that I need to copy ...
0
votes
2
answers
708
views
How to directly call a method with ref parameter using in parameter
I'm using a method from a legacy library: F (ref T t) where T: struct. It's declared as ref for performance reasons only and does not modify the data it receives. This library cannot be altered.
In ...