C# is a multiparadigm, managed, garbage-collected object-oriented programming language created by Microsoft in parallel with the .NET platform

learn more… | top users | synonyms

0
votes
1answer
58 views

Secure way in authenticating credentials when Reading an xml file from the outside source

I started working on a project where I need to read and parse an xml file from a url. This url needs a credentials to successfully read the data from it, so I'm thinking while reading the file there ...
1
vote
3answers
283 views

How can I sell DRY? [closed]

Where I work we have around 10 VS projects in a solution which are identical in functionality (with some different different rules in a few methods) and share many exact methods. They share the same ...
5
votes
2answers
264 views

How does breaking up a big method into smaller methods improve unit testability when the methods are all private?

I'm presently reading Building Maintainable Software by Joost Visser and some of the maintenance guidelines they recommend include: A) each unit/method should be short (less than 15 lines per method) ...
0
votes
1answer
53 views

Create/destroy multiple threads for animations/light effects

I'm developing a program for the Razer Deathadder and Firefly, I am going to create new light effects for the Firefly. I'm doing this in C# with the Colore library. Now these light effects will be ...
3
votes
3answers
224 views

Single Responsibility - is this class doing too much?

I'm redesigning one of my programs which performs certain actions on processes of interest (known as "Monitored Processes" in my program). Some actions I always need to do on those processes are: ...
4
votes
4answers
174 views

Best practice for getting last record inserted in DB

Me and a couple of colleagues are having a discussion regarding the following case: In an OrderStatus table we're keeping track of all the statuses an order goes through in time, including ...
0
votes
0answers
57 views

How to prevent parallel calls to model?

While there is some command running which calls methods on some model, how to prevent concurrent calls for critical places in that model? If multiple requests comes in then they should maintain their ...
1
vote
1answer
45 views

Structuring projects in a solution for interfaces

I had this idea that I would achieve some good automation and separation of concerns as follows: Define an interface, IDataProvider, in a class in a DataMuncher project that needs to both consume ...
1
vote
1answer
178 views

What is wrong with this substring-matching algorithm? [closed]

At a recent interview I was asked to write an algorithm which: Given a string text, and string subtext, finds the starting character positions of each subtext found within the text. "hey hi how are ...
2
votes
1answer
124 views

Algorithm to get all paths in a tree

I have a tree that has n-levels. For example here I have four levels: Each node has two children (except for the last one), however everyone except for the first and last node of each row has two ...
1
vote
3answers
167 views

The best practice for passing formatted string to methods

Though it might be trivial for someone, I find it a little inconvenient when someone formats the string while passing it as a parameter to a method. For e.g. AddMessage( string.Format("{0} (" + ...
0
votes
1answer
71 views

How to automate common tasks in development and production between my computer and our servers? [closed]

I'm working as a web developer. Our server is in MVC ASP.NET (C#) and SQL Server. We also work with wordpress for content, and SVN for integration of code between front end developers and back-end ...
1
vote
4answers
138 views

Should I be using any algorithm to sort/find items, or use a language's built-in ways?

I'm currently a first semester IT student, and I'm wondering if it's better to write my method to find something e.g. in a C# List, or to use any built in method to do these, such as LINQ or .Find or ...
56
votes
11answers
6k views

Does this class design violate the single responsibility principle?

Today I had an argument with someone. I was explaining the benefits of having a rich domain model as opposed to an anemic domain model. And I demoed my point with a simple class looking like that: ...
-1
votes
1answer
77 views

.net Windows app in a web page [closed]

I am developing a feature related to Microsoft Outlook which has support only for Windows library. However, I have to put this into a web page for the users. In the process of consuming the windows ...
-1
votes
2answers
75 views

Hypothetical extension to C# property initializer syntax

In C#, when you call a constructor, you can add one or more property initializers in curly braces: var foo = new Bar() { Armpit = new Flapdoodle() { Limpet = 2 } }; What if that feature were ...
0
votes
1answer
154 views

Which design pattern is it if any for providing a general logger interface?

I have a library where I want to use a logger but I don't have (and cannot) create any interface for it because I'll be using it on different systems that have nothing in common (and won't have). So ...
13
votes
3answers
2k views

Should I avoid using unsigned int in C#?

I recently thought about the use of unsigned integers in C# (and I guess similar argument can be said about other "high level languages") When In need of an integer I am normally not faced with the ...
-4
votes
5answers
211 views

Differences between `throw` and `throw new` and exactly how exceptions “bubble up” [closed]

Can someone please explain the differences in C# between: throw throw new and exactly how exceptions "bubble up" as I've heard they do? In my daily job, I've used just try/catch to mostly ...
0
votes
3answers
184 views

in DDD, should repositories expose an entity or domain objects?

As I understand it, in DDD, it is appropriate to use a repository pattern with an aggregate root. My question is, should I return the data as an entity or domain objects/DTO? Maybe some code will ...
-2
votes
1answer
56 views

Getting a button click from a circuit board to display in a table on a PC [closed]

I'm thinking of making a project in my free time whilst I'm away from university. The idea is that I am a swim coach and I want to record swimmer's times over 2 lengths. So I'll click start on my ...
2
votes
2answers
158 views

Is there a name for this in type theory? Specify that a value satisfies multiple interfaces without specifying the concrete type

I have often wanted the same feature which is asked for e.g. here and in many other questions on SO: Being able to specify that something satisfies multiple interfaces without specifying the ...
2
votes
1answer
109 views

How to Manage Privileges in C# WPF applications

I'm writing my first "large" program in C# and WPF. It's a Database system (MySQL) that has three main items, Contracts, Companies and People. I have the main UI down for the Companies section of the ...
0
votes
2answers
44 views

Double-check locking around initialisation which performs a web request

I've just refactored some code that managed a global state cache of values that didn't have locking to use double check locking. Other than moving the initialisation to a single source (the cache was ...
-2
votes
1answer
39 views

Convention for exception argument order [closed]

Just a quick question about a design pattern for creating custom exceptions. The question is more about the order of parameters. If you can specify more data in the exception, should the parameter for ...
-4
votes
1answer
78 views

How to determine if a type of class implements an interface [closed]

There is something I am missing about the "Type" class. I have this code: List <Type> area_space_components_sorted; public interface Igood{} Assume the list of types has 5 objects in it, and ...
-3
votes
3answers
89 views

Best way to handle variables used in a for loop? [duplicate]

From previous experience, I had always thought that, if you are going to use variables inside of a for loop, it was much better to declare them outside of the loop vs. inside the loop itself. I ...
2
votes
2answers
56 views

Having a TestContext to test methods instead of Dependency Injection

I am working on a legacy code base and I need to find a way to write unit tests for this project. The project has a three layer architecture (UI-Biz-DAL as we call them) and DAL is totally ...
0
votes
0answers
65 views

Generating dual .xlsx files and .htm pages of the same data

Here are my requirements: Generate Excel reports for users, attaching them to emails Additionally, insert hyperlinks into those emails where the user can view the same report on a web page. I have ...
2
votes
1answer
137 views

How does C# remove duplicate instances of static data of constructed types?

Unlike Java, C# does not share static data among entire generic type, but per each constructed type (i.e. Array<int>, Array<string> and so on). Creating those instances does not seem a ...
2
votes
1answer
82 views

Activity Feed Object to Notify Users

We're developing a transactional application in .NET (ASP.NET MVC, C#, Workflow Foundation, EntityFramework), and want to implement a system whereby users are notified of work that needs to be done ...
21
votes
5answers
1k views

Implementing an interface when you don't need one of the properties

Pretty straight-forward. I'm implementing an interface, but there's one property that is unnecessary for this class and, in fact, shouldn't be used. My initial idea was to just do something like: int ...
6
votes
3answers
156 views

Overriding Equals in an unbrittle way

I have a class WorkflowItemSearchCriteria whose instances represent a set of values and references that will be used to return a filtered result set of workflow items based on the given search ...
1
vote
1answer
79 views

Force instance method to using only public memebrs

What do you think about code like this: public class ThisClass { // this method uses only public members public void DoSomething () { ...
-1
votes
1answer
78 views

Speeding up appending text in C# [duplicate]

I'm trying to append text to a large amount of strings (in the thousands), and also do some other string manipulations. However, I have about 60 lines of if/else and string appending and it takes ...
3
votes
1answer
125 views

How to safely and cheaply delete a directory's contents that are constantly being deleted/overwritten

I'm coding something that will check a specific static location's directory, and if it exists, and a certain process has not run in n minutes, it deletes that directory's files and all sub-directory ...
6
votes
3answers
269 views

Why is the most common integer number 32 bits, but the most common floating point number 64 bits?

Coming from a Java and C# background, I've learned to use int (32 bits) whenever I need a whole number, and double (64 bits) when dealing with fractional values. Most methods from their respective ...
2
votes
2answers
175 views

Is equating a variable to a function that takes the same variable bad programming?

Is it improper programming to set a variable equal to the result of a function that accepts the same variable? The languages in question here are c#, javascript and PHP (not sure if this works in C ...
5
votes
0answers
149 views

How do I associate command objects with the right receiver?

I tried to use Command Pattern for implementing Undo and Redo in my project public abstract class Command { protected Form Receiver { set; get; } protected HtmlElement Element { set; get; } ...
2
votes
1answer
175 views

Helper methods of a particular class [closed]

Let's say I have a class that needs some helper methods to do its work. The number of helper methods starts to grow and the size of the class also starts to grow a lot. How should I handle this ...
1
vote
2answers
170 views

How to build a product modeling framework

We have a legacy ASP.Net application (written in c# a few years ago) which allows a factory manufacture a number of custom-made products. Different attributes such as color, length, width, etc. are ...
0
votes
1answer
78 views

Create an item in two different table with auto-increment C# SQL [closed]

First of all, let me apologize because I know my question will be very confusing since my English is pretty bad. I am working on a project for a company, mainly create a system to take care for ...
3
votes
1answer
69 views

Command handler executing commands with different dependencies

Well basically, I have an Engine class that recieves a command as string from the input and passes it to a CommandHandler class which executes the apropriate command. The CommandHandler passes the ...
2
votes
1answer
88 views

Design Pattern for Library Wrapping Extern Methods

I am working to create a C# library that wraps a C DLL to integrate with our test system. The C DLL has probably close to 100 functions that can be accessed and all from the same DLL. I don't need ...
0
votes
3answers
170 views

Best practices in exposing interface

Let's assume I have a class that downloads data from API, cleans it and saves to database. What methods should I expose? class ApiConnector1 { public string GetDataFromApi() { // ... ...
1
vote
2answers
113 views

Thread-safe events — locking on privately held references

I was reading about delegates and events on this webpage to get a better understanding of them and how they relate to each other. While reading, I came across this statement: That goes against ...
0
votes
1answer
67 views

Access rights through database table

I made a login system with access rights (ASP.NET WebForm) and I store the info's in a database table. I don't use the built in feature of asp.net like Forms authentication and webconfig. My question ...
5
votes
4answers
401 views

Why use plus equals += for event registration?

In C#, you register an event like: window.onClick += myHandler; But why use this instead of a "register" method that takes your handler and registers it. E.g.: window.registerOnClick(myHandler); ...
5
votes
1answer
154 views

Call base inside overriden method

I know there are questions about calling the base method inside an overridden method such as this. But what if an overridden method only calls the base class? Is this bad/good deign? It just seems ...
6
votes
2answers
248 views

Does a C# event have to have an object type as its first parameter?

I have a TCPClient class. It has several ClientEvents. Originally it followed the standard pattern public delegate void ClientEvent(object sender, ClientEventArgs e); Only TCPCLient uses this event. ...