333fred
333fred
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
C# is a multiparadigm language, but types are at its core.
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
Being perfectly honest: if that's your first reaction, why are you using C#?
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
But you should really learn about the basic building blocks of C#, like "what is a class", "what is a property", etc
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
Clearly, you know about programming, so you don't need the hello world, I've never seen a line of code in my life
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
Alright. So, my suggestion is to do a few intro to C# things
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
Do you know what properties are?
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
We don't do public fields in C#, we use properties, so that we abstract whether things are actually fields
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
But I would say you're coding very much like this is C++, not C#
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
Nearly certainly class
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
Depends on the context. In your case here, you'd probably take one of a few possible approaches: 1. Use a record for TokenContext, it probably should be one anyways. Then you wouldn't reassign individual properties like you're doing there, you'd with to do non-destructive mutation 2. Use a builder for TokenContexts. That's effectively what you're doing here, you're treating TokenContext as if it was a builder. But combining these two things into one isn't great; you've opened yourself up to bugs because TokenContext is mutable. 3. You could certainly make TokenContext a struct here. It's not the worst idea, given that there's only 5 pieces of data and they can presumably be enregistered by the JIT. In any of these options, though, I would absolutely make TokenContext immutable. After you create a Token, there's almost certainly no reason to permit modification of TokenContext
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
C# is a GC language. Automatic memory management is the whole point
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
No, that is exactly the wrong approach
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
A variable referring to one is actually a pointer to heap data
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
A class is a reference type, and always allocated on the heap
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
In C#, that's the difference between a struct and a class
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
Ok, so TokenContext context is actually TokenContext* context
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
Do you know C?
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
Classes are also known as reference types
39 replies
CC#
Created by Big Chungus on 2/20/2025 in #help
Object passed by reference unexpectedly
Well, that's how classes work
39 replies