All Questions
433 questions
-1
votes
1
answer
228
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 ...
-4
votes
1
answer
121
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 ...
0
votes
3
answers
363
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 ...
-1
votes
2
answers
51
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>();
...
1
vote
2
answers
72
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....
0
votes
0
answers
68
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,...
0
votes
2
answers
99
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
{
// ...
0
votes
1
answer
164
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 ...
0
votes
0
answers
33
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 ...
0
votes
2
answers
143
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)
{
...
-2
votes
2
answers
4k
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 '...
1
vote
2
answers
718
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 ...
0
votes
0
answers
36
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 ...
2
votes
2
answers
206
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)[]
{
(...
0
votes
1
answer
73
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 ...