C#C
C#3y ago
Ziomek64

❔ A property is changed even though it shouldn't?

This is driving me absolutely bonkers but something weird is going on.

  else
             {
                 GraphQLResponse<Data> filt = apiListData;

                 GraphQLResponse<Data> startFilter = filt;

                  foreach (var List in startFilter.Data.MediaListCollection.lists)
                    {
                        foreach (var listEntry in List.entries)
                        {
                            listEntry.CustomListsList = new ObservableCollection<customListItem>();
                            if (listEntry.CustomLists != null)
                            {
                                foreach (var VARIABLE in listEntry.CustomLists)
                                {
                                    listEntry.CustomListsList.Add(
                                        new customListItem
                                        {
                                            key = VARIABLE.Key,
                                            value = VARIABLE.Value
                                        }
                                    );
                                }
                            }
                        }
                    }

                    var filtered = startFilter.Data.MediaListCollection.lists;

                    foreach (var x in filtered)
                    {
                        x.entries = x.entries.Where(x => x.media.Title.UserPreferred.ToLowerInvariant().Contains(query))
                            .ToList();
                    }
                    Console.WriteLine(filtered);

I'm making a local variable at the beginning to which I assign data from apiListData. I'm making some changes on that local variables, especially that foreach (var x in filtered) which filters data. When I do debug point on that console.writeline apiListData from the beginning which was accessed only is affected even though it shouldn't. And don't mind second local variable, I was doing it only to avoid this weird situation kekw Whole .cs - https://pastebin.com/4pezNHzB
apiListData is just raw data that I'm assigning in Refresh task to keep it for filtering purposes.
Pastebin
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Was this page helpful?