© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•12mo ago•
38 replies
Big Chungus

Object passed by reference unexpectedly

Why is the context of
a
a
modified when
context
context
is modified?
        TokenContext context = new TokenContext(0,1,0,0,src); // start = 0
        Token a = new Token(new SortedSet<int>{0,1}, new List<Token>{}, context);
        context.start = 1;
        context.end = 2;
        Token b = new Token(new SortedSet<int>{1,2}, new List<Token>{}, context);
        Console.WriteLine(a.context.start); // 1
        Console.WriteLine(b.context.start); // 1
        TokenContext context = new TokenContext(0,1,0,0,src); // start = 0
        Token a = new Token(new SortedSet<int>{0,1}, new List<Token>{}, context);
        context.start = 1;
        context.end = 2;
        Token b = new Token(new SortedSet<int>{1,2}, new List<Token>{}, context);
        Console.WriteLine(a.context.start); // 1
        Console.WriteLine(b.context.start); // 1
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Object reference set to null
C#CC# / help
3y ago
❔ Object reference not working (unity)
C#CC# / help
3y ago
✅ Object reference error? Using Unity
C#CC# / help
4y ago