Tagged Questions
C# is a multi-paradigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform.
1
vote
0answers
16 views
C# implementation of authenticated encryption
My application needs to implement authenticated encryption using C#. There is a dot net class called encryptAndAuthenticate, but it is only supported on windows 8 or later, and I need the code to also ...
1
vote
0answers
29 views
Checking for win in a Tic Tac Toe board of 9 picture boxes
I have created a Tic Tac Toe game, the board being made out of 9 picture boxes. I need improvements for the if statement in turn_click method to check winning combinations.
...
1
vote
1answer
23 views
Optimize Linq search query with multiple if statements
I have a search function in my class which checks various class property values for null or certain values and queries the database based on those properties. This how my function looks like now:
...
1
vote
1answer
20 views
Copy a stream to a file using Universal .NET
I have answered to a question on Stackoverflow where Andy struggled to cancel a Stream copy to file operation using the Universal .NET Framework:
Apparently, cancelling the cts CancelOperation token ...
0
votes
0answers
26 views
Using T type parameter to clone a collection
I want to clone a collection with the following method and I want to know if it can be optimized
...
1
vote
1answer
31 views
Parsing US addresses without regular expression for performance
Looking for some constructive feedback on Parsing an Address without using Regular Expression in C# for performance purposes.
My aim is to clean the data and to separate it into its respective ...
3
votes
1answer
43 views
Cloning Entity Framework entities
I'm currently writting piece of logic which copies entities from one user account to another. My current strategy in doing this is like that:
Consider the following code:
...
-2
votes
0answers
31 views
Wanting a better MVC to Javascript pattern to get Resource Files from C# mvc into Javascript [on hold]
Currently Resource Files in asp.net mvc c# are the typical file.resx
MVC controller method:
...
1
vote
1answer
40 views
HexToString function returning maximum of 16kb
The HexToString function returning maximum of 16kb even for sources greater than 16KB
...
4
votes
2answers
69 views
Project Euler #23 Non-abundant sums
I'm having trouble optimizing the Project Euler problem number 23 :
A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of ...
0
votes
2answers
64 views
0
votes
1answer
39 views
1
vote
1answer
87 views
Getting price for one firm by week
I've a lot of data whit prices of a product from different firms by week. I've a class named WeekPrice witch contains a list of ...
3
votes
2answers
85 views
Project Euler GUI for Problem #1 through #11
I've been working on the Project Euler problems, so I created a GUI and a Solver class for all the code I've been creating. I'd like to share it with you guys and to get general feedback on my coding ...
1
vote
2answers
69 views
HTTP Response/Request Class
This is just a simple class that you can you use to send requests and get the HTML code. I would like to get feedback on this.
For your request you can set:
URL
Request method: GET or POST
Request ...
2
votes
1answer
45 views
Generating a MySQL query
I'm trying to create a function to return a DataTable with the results of a MySQL query where the program doesn't know the names of the queried columns until run-time.
How can I improve the ...
0
votes
2answers
93 views
Custom Contains() function
I have the following function and I was wondering if anyone could come up with something more efficient.
It just has to split both the content and the search string and determine how many words are ...
0
votes
0answers
23 views
Web api with IoC and database integration tests
I've made integration tests for a major part of my application. I test my dependency injection is set up correctly, creating controllers with it's dependencies going all the way to the database (using ...
1
vote
2answers
85 views
Does open closed principle fit to this case?
I've recently made a test. One of them was to see problems in the following code and suggest refactoring which can provide adding new formats of data:
...
1
vote
2answers
426 views
Are there mistakes in reading file?
I've recently made a test. There were four tasks. One of them was to improve following code:
...
2
votes
1answer
44 views
API controller with database queries
I have the following controller with a couple of database queries and I'd like you to review it.
I've tried to make it clean for other developers but the communication with the database can be ...
5
votes
3answers
124 views
Getting the business day of the month
I'm working on figuring out what the current 'business' day of the month it is. For instance, if it's the 20th, but there are 3 weekends, it would be the 14th business day of the month.
Is there a ...
-1
votes
1answer
32 views
Switch vs Dictionary logic [closed]
I'm arguing here with a colleague over two implementations of how to handle a processing logic:
VERSION 1:
...
1
vote
1answer
15 views
Scoping resources per HTTP request
I am using this code in an MVC application to manage objects that should only have one instance per request.
...
0
votes
1answer
49 views
Skip by Id on large list
This is in ASP.NET MVC, but that shouldn't make a difference. I have a large number of rows in my database for Songs.
...
-6
votes
0answers
26 views
1
vote
1answer
59 views
Parsing an address without regex [closed]
I am looking to improve on this code as it is not fully working properly yet. This address parse separates street number, street name, street type, apartment name and number from a string of a given ...
1
vote
0answers
50 views
Project Euler #11 Largest product in a grid
Question
Link to the exercise : https://projecteuler.net/problem=11
I'm currently working on the Project Euler exercise's and I just finished the eleven exercise. It's working fast enough it takes ...
5
votes
1answer
56 views
TetrisBoard Class in C#
I am writing a Tetris program in C# for programming practice, and I've got it working. This is the second post in a multi-part series. My previous post covered the TetrisPiece. You can view the ...
20
votes
7answers
5k views
Project Euler #7 10001st prime
I decided to start working on the Euler project exercises. I'm doing fine for now but the seventh problem is running quite slow and I can't think of anything to make it work faster. It takes around ...
6
votes
1answer
57 views
Eraser tool for GIF editor
I am making a GIF editor in C#, and I am currently working on the eraser tool. I am not sure what I can do to make it more efficient, because when I make the thickness (diameter) more than 30 (pixels) ...
4
votes
2answers
99 views
Calculating the equivalent value of 2 resistors or capacitors
I started learning C# and this is my first "project". Its main purpose is to calculate the equivalent value of two resistors or capacitors connected in either series or parallel.
I just finished it ...
2
votes
0answers
36 views
First time using entity framework with simple repository
I'm working on updating a GitHub project that I use at work, but I think the person abandoned the project as there is a pull request for it since 2014. At work we use a Repository pattern with ...
5
votes
1answer
58 views
TetrisPiece Class in C#
I am writing a Tetris program in C# for programming practice, and I've got it working. This will be the first post in a multi-part series. Future posts will cover the TetrisBoard (the game logic), the ...
1
vote
1answer
39 views
Type discriminators
Sometimes we need to map a .NET type to some custom nice looking text and resolve it back to the type latter. We could use it while implementing polymorphic behaviors in JSON API, or ...
3
votes
4answers
279 views
-1
votes
1answer
29 views
CodeEval “Read More” challenge [closed]
Here is the task, which is basically to truncate lines of input to 55 characters, or to 40 characters (also stripping a space if it happens to end in a space) and appending ...
-5
votes
0answers
25 views
Shortest path calculation c# [duplicate]
Trying to find the shortest path route between any two cities.
Using a for loop to loop through the lists to find the paths. Any ideas how I can improve the for loop to make it work better and ...
-4
votes
0answers
32 views
Shortest route between nodes c# [closed]
Trying to find the shortest route between two different cities. I've included what I have done below. I am not sure how to fix it and make it work properly.
...
2
votes
0answers
27 views
Multitenant app authorization
Role based security does not work for me well in a multitenant app, as I need to query DB to decide on permission allowance. Here is the solution I came to.
All implementations of this interface will ...
1
vote
0answers
30 views
Identity repository pattern with UnitOfWork, GenericRepository and Unity
I created an application from 3 layers, DAL, BLL, and Representation layer in ASP.NET Web API. In DAL i have 4 Classes:
- DatabaseContext.cs, UnitOfWork.cs, GenericRepository and UserInfo. In BLL i ...
3
votes
1answer
80 views
Implementing a filter
I have implemented a filter for filtering a IEnumerable of a specific type.
To accomblish this goal i have created three classes: ...
0
votes
0answers
35 views
Authentication terminology
Below comes a Value Object to represent UserId in ASP.NET application. It implements Value Identity, so equality is defined by matching of the state calculated at ...
2
votes
1answer
35 views
Injectable logging with NLog and Ninject
I have been using NLog for logging purposes in my web applications, but it was not injectable. More precisely, each class using logging declared the logger like this:
...
2
votes
1answer
51 views
Finding corners from Line arrays
I have the following code that takes input of Line arrays and attempts to find the intersections on the end points between them. The value ...
1
vote
1answer
33 views
Finding the nearby points from an array
I have the following code that takes a Point and a given tolerance value and looks for all other Points that fall within the ...
1
vote
0answers
24 views
Automatically close popup after a certain period of time
There is a Popup in my application which I want to close automatically after a certain delay. And I want to have an attached behaviour which I could turn on/off and ...
5
votes
1answer
88 views
MVVM: Am I doing it right?
I read a lot of articles recently concerning XAML, WPF, data binding and MVVM. I also watched some MVVM tutorials and downloaded some MVVM samples. I finally got my first MVVM sample to work, but ...
1
vote
2answers
59 views
Manage connection string
I'm using dapper-dot-net for data access in my ASP.NET MVC application.
So in order to supply a connection string I've came up ...
5
votes
2answers
73 views
A more generic `DelegateCommand`
In an effort to create ever-improving code, I've written a DelegateCommand that takes a generic type parameter to be acted upon. It's pretty trivial, so it should ...