Skip to main content

All Questions

Tagged with
-1 votes
1 answer
87 views

C# - WPF - Display list of strings

When I search the equivalent of foreach in xaml WPF, I get ItemControl tutorials, but it is only about presentation it does not solve the iteration part of it how do I do this in WPF ??? <TextBox ...
pf12345678910's user avatar
-4 votes
1 answer
86 views

C# For loop with try catch finally

I am trying to run for loop for every 5 secs to get the readings from COM port. When successful getting the readings only once. Would like to run the loop even if there is error. sometimes the ...
Diya's user avatar
  • 1
0 votes
3 answers
202 views

What is the most efficient way to increment all values of a dictionary in c#?

I have hundreds of dictionaries where all the values of all the dictionaries need to be incremented by 1. What is the most performant way to do that in C#? I thought of iterating through the keys ...
osman doluca's user avatar
-1 votes
2 answers
45 views

How to create List<T> instance in C# when using reflection [duplicate]

I have a class with some Generic Properties in it and also some other types of property: private ObservableCollection<SelectFood> _breakfasts = new ObservableCollection<SelectFood>(); ...
Khosro's user avatar
  • 3
1 vote
2 answers
70 views

Why does 'total' not exist in the current context?

I am trying to print n to the power of p without using Math.Pow(). Here is the pseudocode: get two integers n , p from the user using a for-loop calculate the power function n ** p without using Math....
Hash Slinging Slasher's user avatar
0 votes
0 answers
65 views

Returning a new list of every nth element in a linked list. C#

I am writing a method that takes in an integer "nth" that operates on a linked list of generics and returns every nth element. If the list is 0-99 and nth is 10, it should return a list of 0,...
Snipermtd24's user avatar
0 votes
2 answers
92 views

Why is the first timed function always measured to be faster with `Stopwatch`

I am trying to establish is iteration or recursion is faster in C#. However, on a simple test, I cannot seem to get trustworthy results using StopWatch. Code: internal class Program { // ...
D.Man's user avatar
  • 185
0 votes
1 answer
90 views

Nested foreach that depends on variable of the previous foreach

I've wrote a piece of code that correctly loops trough lists and does what I need, but I think it's a bit stupid how I did it, and I'm looking for a way too write this effectively, with a while, or ...
ng80092b's user avatar
  • 667
0 votes
0 answers
28 views

How can i extract the event subscription in an own method without reducing performance

I have a WPF Application where I regularly have to convert DataTables from a SQLClient into ObservableCollections of models. In order to reduce code I have created an extension Method called ...
Azzarrel's user avatar
  • 573
0 votes
2 answers
96 views

How can I fix my C# for-loop implementation of sorting in descending order that fails to iterate until the last element?

Write a method that finds the biggest element of an array. Use that method to implement sorting in descending order. static int FindBiggestElementIndex(int position, int[] arr) { ...
Sarah Shaygani's user avatar
-2 votes
2 answers
3k views

How do I iterate over a JsonObject with foreach in C#

I'm trying to foreach through a JsonObject, but unfortunately it gives me an error on the "in productSizes" foreach statement cannot operate on variables of type 'JsonNode' because '...
Ednik's user avatar
  • 17
0 votes
2 answers
582 views

How to iterate through a C# object's properties and update the corresponding property on another object

I have to objects of the same type, one source and one destination. What I'm attempting to do is iterate through the source object properties, and if it has a value, update the corresponding property ...
Cef's user avatar
  • 789
0 votes
0 answers
34 views

How to create jagged arrays which consist of 3 number of arrays (i.e. Arrays of arrays of arrays )?

I want to create Boxes in a 3-dimensional grid. To create the same, I stored the number of x,y and z elements in each array and iterated to produce boxes in 3D grid. C# ScriptError message I expected ...
mk95's user avatar
  • 1
2 votes
2 answers
155 views

Forward-only one-pass stateful IEnumerable<T> to IEnumerable<IEnumerable<T>> with no interim storage?

I want to take streamed IEnumerable values such as: (Tuples shown for illustration purposes. The actual application will be streaming DataRecords from a DataReader) var tuples = new(int, int)[] { (...
amonroejj's user avatar
  • 633
0 votes
1 answer
63 views

Dispense/Distribute BankNotes depending on their inventory

I created this method, I have a list of bankNotes {1, 5, 10, 20, 100} each has 10 notes, Everything in my code works fine but it seems like it is not efficient enough when calculating the notes and ...
user3068888's user avatar

15 30 50 per page
1
2 3 4 5
29