Questions tagged [in-parameters]

8 questions
17
votes
4 answers

Using C# 7.2 in modifier for parameters with primitive types

C# 7.2 introduced the in modifier for passing arguments by reference with the guarantee that the recipient will not modify the parameter. This article says: You should never use a non-readonly struct as the in parameters because it may negatively…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
5
votes
1 answer

C# 7.2 use of "in parameter" for operators

In C# 7.2, we saw the introduction of the in modifier for method parameters to pass read-only references to objects. I'm working on a new .NET Standard project using 7.2, and out of curiosity I tried compiling with the in keyword on the parameters…
Sean M.
  • 113
  • 2
  • 7
5
votes
3 answers

Dodging the performance hit from using `in` with a struct without making the struct readonly?

C# 7.2 added two new features: In Parameters Using in for a parameter let's us pass by reference, but then prevents us from assigning a value to it. However the performance can actually become worse, because it creates a "defensive copy" of the…
AustinWBryan
  • 3,249
  • 3
  • 24
  • 42
4
votes
1 answer

Why do C# 7.2 features not compile in a UWP application?

... in particular, in (readonly ref) parameters. Here's my situation: I have a UWP project and a UWP Unit Test project in the same Visual Studio solution. Both projects target C# 7.2 The main UWP project has this class (note the in…
Steve Dunn
  • 21,044
  • 11
  • 62
  • 87
2
votes
1 answer

How to create a generic type on the Action delegate with a ByRef parameter?

I am trying to create a delegate on an Action<> type with a by-ref parameter as argument. But I am stuck on how to achieve this. That's what I got so far: using System; class Program { struct MyStruct { } static void FooFn(in MyStruct s) {…
2
votes
1 answer

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 struct: public struct Quaternion { public float…
Ray
  • 7,940
  • 7
  • 58
  • 90
1
vote
2 answers

related to "IN parameter" in mysql

when i GOOGLED about IN parameter i got this.. the value of an IN parameter is protected. It means that even if the value of the IN parameter is changed inside the procedure, its original value is retained after the procedure ends (like pass by…
0
votes
0 answers

How to create a dynamic method in C# which uses an "in" parameter?

I try to create a dynamic method in .NET which has an "in" parameter, but it throws an exception in the EmitCall line: public struct Context { public string MyString { get; set; } } public interface IHandler { void MyMethod(in Context…
zgabi
  • 404
  • 1
  • 4
  • 11