Questions tagged [c#]
C# is a multi-paradigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform. Use this tag for questions related to C#. In case a specific version of the framework is used, you could also include that tag; for instance .net-2.0.
799
questions
1
vote
1answer
1k views
ASP.NET MVC application architecture fit for unit testing with mocking
I am trying to learn how to professionally work with unit testing, so I have refactored a medium sized project of mine (a sort of article aggregator that also does some NLP processing) and tried to ...
1
vote
1answer
3k views
Unit testing - test class inheritance vs single test class [closed]
Which unit testing approach and WHY do you prefer?
Inheritance-driven-testing
...
1
vote
2answers
108 views
Threadsafe filtering queue
I have implemented a thread safe filtering queue. The queue allows any objects, of the specified type to be added. A thread interested to take an object must specify which object it is interested in ...
1
vote
1answer
266 views
Simple PacketHandler class [closed]
I can recently coded an emulation system and in this project I have a PacketHandler for each player connected to a socket server, and each player receives packets (data) from the client application.
...
1
vote
0answers
50 views
C# asynchronous notification vector v2
As a result of my previous post, I have implemented / refactored my code and have started making successful use of my class. However I have come across a couple of new questions:
The observer must ...
1
vote
1answer
178 views
A Generic “Augmentation” Collection for RPG Attributes/Resistances/Aversions
After having showed a previous implementation of my "Resistance System", I decided that I was completely wrong about how I had been going about things. The system, as it had been presented, was ...
1
vote
0answers
727 views
Secure password hashing implementation with salt and pepper
I share below my password hashing implementation with salt and pepper in C#, for your review and feedback. In my implementation methods like ValidatePassword(), ChangePassword() are in the user class.
...
1
vote
3answers
397 views
Combine neighboring parts of an array based on a condition
I have written this code which takes a one dimensional array, for example:
{"abc","ade","sss","fgw","asd","lka","o"}
and turns it into an array of arrays, ...
1
vote
1answer
187 views
Change implementation from getting json from file to get it from API
I used to get a JSON file with some configuration settings from the file system, using this class:
...
1
vote
3answers
97 views
How to correctly get a IDisposeable when you need to lock the factory?
If I need to create a IDisposeable object from a factory, but if the factory object is not thread safe and requires me to lock on it is this the correct pattern to use?
...
1
vote
1answer
3k views
Custom Exception.ToString() formatter
I find the default Exception.ToString() formattig very difficult to read especially if there are inner exceptions involved. I guess everyone knows how it looks:
<...
1
vote
1answer
124 views
Choosing/creating/setting an NPC dialogue - follow-up
Initial post: Sequentially displaying a list of game objects
This file creates a dialogue box and sets the chat history box too inactive. It finds which NPC dialogue to display, creates the list and ...
1
vote
2answers
203 views
Best C# implementation of IndexOfAny(string, params string[])
Follow-Up question
.Net provides String.IndexOfAny(string, char[]) but not String.IndexOfAny(string, string[]).
The existing ...
1
vote
1answer
94 views
Simple and reusable system for user registration and tracking and auto-updates - follow-up
This is a follow up question of this one.
Since the original question was posted, it has turned out that in some cases I want the code to be synchronous and in others to be async.
I have updated the ...
1
vote
2answers
620 views
WPF wizard-like app
I'm designing and developing wizard-like app for populating the database I created with data from different sources. It's my first attempt to design and develop well-structured object-oriented ...
1
vote
1answer
6k views
Excel-to-JSON parser
I just wanted to build a simple converter from an XLS Excel file to JSON. I have predefined JSON format. All fields except of two - are just simple mapping from Excel to JSON. The two fields have a ...
1
vote
2answers
818 views
Preparing code for more versatile CRUD functions
I am using C# and the .NET entity framework, and I'm also learning how to better use OOP concepts in my program. My code is all displayed below. I would like to ensure my logic is properly organized ...
1
vote
2answers
64 views
IsoSettingsManager
Just a wrapper around IsolatedStorageSettings.
The only thing i'm not sure about is isoSettings.Save(); Should i call it there? Looking like it works without it, setting [] is enough.
...
1
vote
1answer
672 views
Using Models and Entities in MVP pattern
I'm a beginner in MVP design pattern and In a MVP triad, I have
Model - AdvanceInfo
View - AdvanceForm
Presenter - ...
1
vote
2answers
400 views
EF Code First Identity/Info Storage
I've built this EF for storing data for web scraping. Any ideas? What am I missing?
...
1
vote
1answer
99 views
News-reading application using the Observer pattern
I have found this question online from an Amazon interview:
Design a kind of Kindle Fire application where we can subscribe to a news
channel and read the news from all publishers as a digital ...
1
vote
1answer
2k views
Single player console Blackjack game
This is just a single player versus a dealer. I'm not worried about execution time. It does not perform bets - it only track wins and losses- and has no splitting. Other than that I tried to get it ...
1
vote
1answer
41 views
Declarative DependencyProperety registration
Most properties have simple requirements so it should be possible to register their Dependency Property fields declaratively.
I made a small experiment and it seems to work just fine. The first ...
1
vote
1answer
314 views
Dynamic CSV Formatter
I made a dynamic CSV formatter as a personal challenge after having to hardcode a behavior to convert some data to CSV earlier. You input any List that contains supported types as properties (all ...
1
vote
1answer
74 views
Sequence to extend and forget
After receiving some feetback about my previous attempt to create reusable, easily extendable sequence generators I try once again to create such a framework.
This time there is no inheritance. Just ...
1
vote
2answers
578 views
C# Chat - Part 1: Server
I've been building a simple C# server-client chat-style app as a test of my C#. I've picked up code from a few tutorials, and extended what's there to come up with my own server spec.
In this post (...
1
vote
1answer
63 views
Interfaces & Factory for generic container supporting PeekMax, PeekMin, Sum, and PeekNextToMax
This is a partial update of this question.
An implementation of these interfaces is in this question.
To summarize, the class is a generic container similar to MaxHeap, but only needs to support the ...
1
vote
0answers
332 views
Entity Framework 6.0.2 - Performance of Auditable Change Tracking Part 2 of 2
This is Part 2 of a question about performance and general best practices. Part 1 is located here. The body of the messages are the same to illustrate their similarity, the difference is the code ...
1
vote
1answer
73 views
Multithreading extensions
I created a following class to manage multithreading without extra overhead, which exist when I use Parallel TPL class. It is also useful for systems without ...
1
vote
1answer
146 views
Database abstraction class in C# (version 2)
Below is my revised version of this code after I acted on the suggestions:
Database abstraction class in C#
...
0
votes
0answers
89 views
Bank ATM App Mockup - Implementing Domain-Driven Design (DDD)
There is a follow-up on this question.
I have created this bank ATM app mockup which I believe implement some Domain-Design Design layered architecture, repository pattern and uow pattern, if not ...
0
votes
1answer
632 views
Refactoring to avoid the use of dynamic
Based on the answer to my question on StackOverflow, I have ended up with the following code:
...
0
votes
2answers
116 views
Date of Birth Value Object 2
I realize it could be argued that it is an overkill to create a ValueObject for such a simple type. I am just trying to make sure that I understand the principles of overriding/overloading these ...
0
votes
2answers
162 views
Switch-Case pattern for non-constant types [closed]
Edit: Following answers, I modified my code, and wrote an other question.
History
Recently, I (stupidly) tried to make a switch on myObj.GetType(). Of course, it ...
0
votes
2answers
744 views
Implementation of asynchronous (?), self-refreshing cache of object collection bulk
I'm trying to create a caching solution used in various parts of a clients' application. The resulting code will be open source.
For example, it will be used for caching API queries like "get all ...
0
votes
1answer
665 views
Simple logger class in C#
I've been using logging libraries recently and somebody told me to try and write my own. I've kept it minimal but the only drawback is I can't log in static classes, due to TClass.
Follow-up
I'm ...
0
votes
2answers
285 views
Common Implementation for Sending mail based on time
I have created one Background service that execute after every 5 minutes and this service used for sending email after 6 hour,24 hour and 48 hour for user booking order is not confirmed.
for that i ...
0
votes
1answer
223 views
Calculate min/max values for signed or unsigned integral number with any valid number of bits (up to 64) [closed]
This came up when I answered another post.
Is there a better way?
...
0
votes
0answers
887 views
Bank ATM in C# Console Project
Sort of completed my bank ATM in C# console project. What do you guys think of the structure/design of this whole solution? There are 2 console projects ( Bank Admin and Bank Customer) and the third ...
0
votes
2answers
2k views
Palindrome algorithm
This code could be better?
This is the algorithm:
Compare the 1st character to the last character
Compare the 2nd character to the second last character and so on
Stop when the middle of the ...
0
votes
2answers
10k views
Inventory Script (RPG) in C# [closed]
I would prefer if more experienced users could give pointers on how I can optimize and think better when writing code.
If you are unfamiliar with unity3d, ignore the use of UnityEngine, the heritage ...
-1
votes
2answers
154 views
BubbleSort - checking if bubblesort is decreasing the iterations through the array
What I'm hoping my code is doing is instead of making 99 comparisons on every pass of a 100 element array, it will now make 98 comparisons on the second pass, 97 on the third pass and so on and thus ...
-1
votes
1answer
510 views
Thread-safe queue mechanism
Is it my queue mechanism thread safe? I just wonder if I need concurrent collections. Need I lock Enqueue method? Console displays queue count in incorrect order, Does it affect on maxQueueCount at ...
-1
votes
2answers
86 views
Extending IdentityUser with nullable foreign key to another IdentityUser [closed]
I'm working on a framework which builds on .net core Identity. Let's say I wanted to extend the IdentityUser<TKey> class with a ...
-1
votes
3answers
153 views
Base 256 array addition Recursively [closed]
Is there any way to improve private byte[] RecursiveAdd(byte[] f, byte[] s, int index, byte[] result, bool carry = false) method? The method signature is too long ...
-1
votes
4answers
284 views
Remove “b” and “ac” from a given string
I coded this solution for this problem:
Given a string, eliminate all “b” and “ac” in the string, you have to replace them in-place, and you are only allowed to iterate over the string once
Seems to ...
-1
votes
1answer
42 views
-1
votes
4answers
1k views
Finding the lowest terms for fractions in C#
I have been working on this Rational Operations calculator where you can input two rational numbers and can add, subtract, multiply and divide and the final output is the reduced answer.
For example: ...
-4
votes
3answers
6k views
Write object data to CSV files [closed]
Does this method follow the rules of objective programming? If not, how can I change it?
...