Tagged Questions
6
votes
3answers
54 views
Searching all diagonals of a 2D M x M array
I've started writing a piece of code to help me search for an object in all the objects found in the diagonals of an M x M 2D array.
Though the code works, I'd like to know if there is a way I can ...
1
vote
1answer
45 views
Making an email text-parser generic using PredicateBuilder
I have some code that reads an email from a text file, parses the text, removes some lines (the 'cc' and 'to' lines) and then finds the line numbers of various phrases (e.g. "Regards", "Thanks") and ...
9
votes
1answer
248 views
Update first and last item in List<T>
I am trying to do the following. I have a list of Custom objects:
...
4
votes
3answers
130 views
7
votes
5answers
505 views
5
votes
2answers
164 views
Efficient way to get every unique combination of “Pick 1 number from each Group of Numbers”
My question is: Using C# and/or Linq, how can this existing code be improved to be more efficient? (My "Complex" example takes about 5 seconds to run, how to make it faster?)
What the code is ...
4
votes
1answer
142 views
IndexOrDefault that functions like FirstOrDefault
I don't know why this is not in the .NET Library, but I need to be able to use an index against a list and not have it throw an exception if it is outside the bounds of the list.
This is what I came ...
6
votes
4answers
168 views
7
votes
4answers
322 views
File text searcher
I have a working version of a logfile searcher that targets a specific directory by extension type, and searches the files for certain words.
I'm wondering if my method is the most efficient ...
10
votes
2answers
13k views
LINQ to SQL Joining Entities
I have two tables, one for jobs, and one for the names of industries (e.g. automotive, IT, etc).
In SQL I would just do:
...
5
votes
1answer
86 views
6
votes
1answer
113 views
Refactoring a LINQ query that (sometimes) returns null
I have the following LINQ query that should return a result for each Request. I'd prefer to have the query translated to ...
5
votes
1answer
71 views
Combining List<>.ForEach and List<>.Zip
I have three lists, and I need to operate on the ith element of each list simultaneously.
...
4
votes
1answer
67 views
Convert hex string to byte array
The goal is to convert a hex string to a byte array with the following requirements:
\$O(1)\$ additional space apart from input and output.
\$O(n)\$ runtime
This mostly just prohibits creating a ...
5
votes
2answers
90 views
Adding object to database, using linq or sql connection
I have a table called tblDelegates in my database which I need to populate with some data. I have created a class called Delegates which has various properties to ...
4
votes
2answers
84 views
Create a LINQ Killer Sudoku Cage Solver
When playing Killer Sudoku I find myself repeatedly writing stuff like this:
12/3
921
831
741
732
651
642
543
and then crossing out the combinations that include ...
5
votes
3answers
225 views
8
votes
4answers
1k views
How to optimize these nested loops for better performance?
I need to optimize this code so it can execute faster, even if that means using more memory:
...
6
votes
3answers
269 views
Get distinct combinations of numbers
The below code returns all distinct combinations based on the logic that 1,2,3 = 3,2,1 = 2,3,1, so it only returns 1 instance of that set of numbers.
...
8
votes
1answer
628 views
Multiple repository calls or LINQ query
These two methods do the exact same thing (or at least they are supposed to!). They both pass a simple test based on a mock context. Neither has been exposed to any integrated testing yet.
Would ...
8
votes
2answers
169 views
Take previous element from array if condition on current element matches
Any ideas to simplify this beauty; I would prefer a LinQ expression if possible:
...
6
votes
2answers
217 views
Web service getting value using LINQ from queue table in SQL database
As a test of my C# skills, I have been asked to create a simple web service which will take a message from a queue table in a SQL database and send it to a web application when a button is pressed on ...
2
votes
1answer
67 views
Is there a better way to do this linq sort?
I have the following linq statement that is ordering a list of assets by the sort order of a child item:
...
2
votes
2answers
210 views
Sum(), ForEach() with Lambda in a hierarchical List Collection
I have to list the number of documents related to items in a hierarchical tree.
The specification states:
The tree will only ever be 2 levels deep.
The higher level items will list not only the ...
5
votes
4answers
2k views
Sieve of Eratosthenes in C# with LINQ
Can someone look over this Sieve of Eratosthenes implementation? It seems almost too easy.
Rather than maintaining a seperate bit[] to track prime/not prime, I'm ...
3
votes
2answers
187 views
Extracting Pixels From Image Byte[]
I have a requirement where I need to extract pixels of a given rectangle within an image byte[].
More specifically I have an image where I have narrowed an area ...
2
votes
2answers
79 views
Mixing Linq queries and Linq lambdas
I have been given a change to rewrite an old framework we use, and to implement the repository and unit of work patterns, but in an attempt to not rewriting all queries I have ended up with a weird ...
3
votes
3answers
128 views
Test questions - Number Generator, Linq, Delegates, Sequences
I have recently been asked to do a test prior to an interview to test my C# skills. I am fairly new to C# (6 months) and I think this showed with me producing an overly complex answer to their ...
12
votes
4answers
939 views
Calculating totals of a transaction
I am working on a project where I have to calculate the totals of a transaction. Unfortunately, coupons have proven to be quite an issue. There are four types of coupons: transaction percentage, ...
6
votes
2answers
636 views
Generic Calculator and Generic Number
.NET does not support generic numbers. It is not possible to enforce a generic method with generic argument T that T is a number. The following code will simply not compile:
...
4
votes
1answer
395 views
Linq queries performance
I am fetching data from the database using entity framework and linq queries. I am wondering about the performance of getting data.
Here is my code. I just want to check that a Well exists in ...
3
votes
2answers
82 views
Copy two properties from one array item to matching index in another array
I have two IEnumerable objects called items and newItems. I need to update the Did and ...
7
votes
4answers
1k views
Single line FizzBuzz solution in LINQ
Now FizzBuzz itself isn't a big challenge but I agree that it can be a good tool to see if someone can code or not. I wanted to practice my LINQ a little bit so here's my single line FizzBuzz ...
2
votes
2answers
72 views
Add chat to an MVC database: Can I condense this code and is it appropriately placed?
I have these relevant tables in an MVC website:
Server
ServerPlayer
ServerPlayerChat
Servers have serverPlayers, ServerPlayers have ServerPlayerChats. Simple enough and expectable.
I'm using ...
5
votes
2answers
190 views
Getting list of daily team goals
The old code I had before was atrociously slow but after some advice and research I was able to take a 2-5 minutes run time down to about 5-30 seconds. That is acceptable, but still looking to have ...
4
votes
3answers
1k views
VersionString (eg “1.0.2”) IComparer algorithm
For a project I'm working on, I need to compare version strings where:
version strings are composed only of numbers and periods
version strings are made up of an arbitrary number of segments ...
2
votes
1answer
68 views
Compare Collection with the information in DB using EF and LINQ
I want to inform the Receivers about new contracts we have this week. After I sent the Emails, the Information about sent contracts are stored in MS SQL Database.
To avoid that someone become the ...
4
votes
1answer
114 views
EntityFramework-based filtering
I am trying to use the following form to enter new info into a database.
I am trying to use the entity framework.
I have the following classes of Interest:
...
1
vote
2answers
12k views
Inserting Data in The Database using LINQ TO SQL
Can this Code be any shorter? because it seems it is very long with just simple insertion of data using LINQ TO SQL
...
10
votes
5answers
457 views
5
votes
3answers
154 views
Calculating total sales from each member
I am building a new system that is using some tables from an old system.
For each user on this new system, I need to go to the old system and total up their sales. Currently it takes between 2-5 ...
11
votes
6answers
756 views
Increment up the build number in AssemblyInfo.cs on every build
I just wrote this short little program to increment up the build number for my projects every time I build them.
After compiling this exe, I just call it in the pre-build command line.
I did take ...
4
votes
1answer
90 views
Am I even using the Entity Frameowrk and/or LINQ the way it is supposed to be used?
I feel like just because the below works doesn't mean it is correct, I want to improve it but I can't really figure out how. Besides the fact it is down right ugly I feel the performance could be ...
2
votes
1answer
330 views
DateTime filter
I have been trying to optimize the filtering process of a Collection<Alert> based on the DateTime GeneratedOn property of ...
10
votes
4answers
454 views
Generate sequence in Linq
I want to generate a sequence using Linq that goes from 10 to 100 with a step size of 10. The sequence also must contain a custom value (in the correct order).
This is what I have now, and I'm ...
3
votes
1answer
178 views
Parsing notification information from distribution lists
I'm writing am application that I've previously posted questions on here, but I'm looking for similar advice if possible. I am looking for how best to write my code, as I have a working example, but ...
4
votes
2answers
87 views
Retrieve Tasks by Employee
I think I've done a decent job keeping this query simple and understandable, but I'd like to know if you have some more advice.
My relevant entities are defined like this:
...
13
votes
4answers
10k views
Is the LINQ version faster than the foreach one?
Since I don't know how LINQ works under the hood, I can't decide what version is best to use in term of rapidity of execution. I've done some testing with my testing data (Point Cloud) but I can't see ...
1
vote
2answers
187 views
Converting Anonymous To Dynamic [closed]
I have a extension method like following that takes Anonymous type objects and returns it after converting into ExpandoObject which falls under ...
0
votes
0answers
128 views
Can this DbGeography calculation be done better?
Given the following piece of code, can it be done better:
...