in Education by
Below is a crude for-loop to illustrate what I need to do. Basically, if there are any 'Variable' objects with property 'Name' containing the text "TCC#", then I want to change the 'Type' property (not the .Net type) to 'VariableType.Text'. The code is going to run over 4800 ParsedCard variables and currently takes a stupid amount of time (about 10 minutes) to simply iterate through the list and write a line to the Debug console. ParsedCard has IEnumberable Functions which have IEnumberable Groups which have ParseResults which have IEnumberable Variables This is such a simple problem but I've tried all sorts of variations using LINQ but can't find anything that performs well (less than 10 seconds). private void AdjustTCCVariables(IList parsedCards) { for (var i = 0; i < parsedCards.Count; i++) { var parsedCard = parsedCards[i]; for (var j = 0; j < parsedCard.Functions.Count(); j++) { var function = parsedCard.Functions.ToList()[j]; for (var k = 0; k < function.Groups.Count(); k++) { var group = function.Groups.ToList()[k]; for (var l = 0; l < group.ParseResult.Variables.Count(); l++) { var variable = group.ParseResult.Variables.ToList()[l]; if (variable.Name.Contains("TCC#")) { //variable.Type = VariableType.Text; Debug.WriteLine($"Need to change variable at [{i}][{j}][{k}][{l}]"); } } } } } } I've tried with this LINQ but it doesn't actually change the 'variable.Type' of the input list (I suspect because it creates a new copy of the objects in memory and the assignment isn't actually affected the 'parsedCards' IEnumerable at all: private void AdjustTCCVariables(IEnumerable parsedCards) { var targetVariables = parsedCards.SelectMany(x => x.Functions.SelectMany(z => z.Groups)) .SelectMany(x => x.ParseResult.Variables.Where(v => v.Name.Contains("TCC#"))); ; foreach (var variable in targetVariables) { variable.Type = VariableType.Text; } } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
As mentioned, the bottleneck in your iterations is the .ToList() calls. Since you mention that you only want to edit the variable.Type property, I would solve this like this. var variables = from parsedCard in parsedCards from function in parsedCard.Functions from group in function.Groups from variable in group.ParseResult.Variables where variable.Name.Contains("TCC#") select variable; foreach (var variable in variables) { variable.Type = VariableType.Text; } You don't need to know anything other than the variable objects that need changing, you don't need all the indexes and all the other variables. Just select what you need to know, and change it. This way you will not know the indexes, so your Debug.WriteLine(...); line won't work.

Related questions

0 votes
    Below is a crude for-loop to illustrate what I need to do. Basically, if there are any 'Variable' ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I am working with Entity Framework for a while but still have some "black holes" with how it is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 20, 2022 in Education by JackTerrance
0 votes
    I want to optimize this code instead of using td(String.valueof(dataset.get())) mutliple times. I ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    R comes with a ________ to help you optimize your code and improve its performance. (a) debugger (b) ... Analysis of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Which component is responsible to optimize bytecode to machine code? (a) JVM (b) JDK (c) JIT (d) ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    How can I clone or deep copy an object so that the cloned object can be modified without any changes being reflected in the original object?...
asked Jan 15, 2021 in Technology by JackTerrance
0 votes
    Whenever an enterprise makes a decision, it deeply considers the effect it will have on its end users. What is this statement describing?...
asked Nov 28, 2020 in Technology by JackTerrance
+1 vote
    What is the correct code to have the following output in C using nested for loop?...
asked Nov 8, 2020 in Technology by JackTerrance
0 votes
    object looks like as below { "id":1, "image":"path/to/image", "employee_data":, } again ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    object looks like as below { "id":1, "image":"path/to/image", "employee_data":, } again ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I was unable to find a solution that is identical with the issue I am trying to solve. If is a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I was unable to find a solution that is identical with the issue I am trying to solve. If is a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I am developing an application with Rails 3.0 and Backbone and I tried asset precompilation (rake assets: ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Suppose I am writing a function fromPaths(paths: List[String]): Node to build a tree from a few ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I am retrieving messages from an Outlook account. I am trying to get inline files and attachments from ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
...