C
C#11mo ago
Spesceptic

Simple newbie problem I need someone to explain to me

See the two screenshots, the first one assigns the changed value by using x = ChangeValue(x); while the second tries to change the value by only calling the method ChangeValue(x); but it doesn't work. I would like to know why? Since it already calls the method that returns the value of x, and it has the argument set up, why does it still not work and it is necessary to assign the method to x ? I hope I explained it clearly! I'm very new.
4 Replies
SinFluxx
SinFluxx11mo ago
Once you've passed x into the ChangeValue method it's no longer working on the x variable itself, it's just working with the value of x, it no longer has any connection to x, hence why you have to assign it afterwards like your first example
Spesceptic
Spesceptic11mo ago
aaah understood
SinFluxx
SinFluxx11mo ago
You can pass arguments to a method by reference, which let's them work with the original variable itself https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ref
Spesceptic
Spesceptic11mo ago
thank you so much mate got it
Want results from more Discord servers?
Add your server
More Posts
❔ Azure AD B2C user - password resetHello, I need some help with Azure AD B2C user flows and custom policies. In my current project, I h✅ How to "preview" text in a DataGrid```xml <DataGridTextColumn CanUserReorder="False" CanUserResize="False" Width="*" Header="Diary Entr✅ An API refuses my Connection from MAC but not Windows.Hello there!! Could you give me a hand with this? I'm using MAUI & Blazor. Previously, I didn't ge✅ ✅ User's required to have .NET installed when launching application???https://github.com/mekasu0124/Todo I created my own Todo application, and using Visual Studio to bu❔ Find last element in dictionnary, using a list as pathHey, I have a dictionnary: ```c# Dictionary<string, object> tree => new() { { "show", ❔ AWS DDB and Lambda integration doesn't workAs mentioned in the title, I have created a DDB - Lambda - API gateway construct according to this t❔ c# .net6 cryptograpy exampleHello. I'm searching for an example for encryption. I already looked at: https://learn.microsoft.co❔ Call base method in multiple inheritanceExample of what i have: ```CSharp public class A { public virtual void Foo() { Console.Writ❔ Change datatype during program executionI have following two properties: private ContextType ExportContext = 0; private List<T> SelectedIte❔ Is there a way to override a Variable in the .csproj by a project that is reference this project?Is there a way to override a Variable in the .csproj by a project that is reference this project?