C# is a multiparadigm, managed, garbage-collected object-oriented programming language created by Microsoft in parallel with the .NET platform
-3
votes
0answers
11 views
How to store, list, open files to MySQL using C#
Im creating a c# employee app, I've created a form for Employee files and I dont have any idea how to store list and open files to mysql with c#.
Any help with detailed example will be aprociated!
...
2
votes
1answer
54 views
Redundancy caused by polymorphism
I have two chat rooms, one has administration behaviour, and one doesn't. I have factored out all of the common code into a base chat room, but the AdministerChatroom behaviour I have pulled out into ...
0
votes
0answers
4 views
Displaying Fibonacci sequence [migrated]
wrote a program to calculate and display the first 20 fibonacci numbers, the sequence goes as follows:
1, 1, 2, 3, 5, 8, 13... (each number is the sum of the previous two numbers)
The problem is ...
0
votes
0answers
6 views
Displaying numbers in increasing numerical size using 'bool' [on hold]
i wrote a program to take numbers from 3 trackbars and put them in increasing numerical size , but whenever i try to display them in increasing numerical size in a label or message box it says all ...
-1
votes
1answer
65 views
Pros and cons of using generic delegates as nested functions
I've written code like this before:
private void Strings_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
var onAdd = new Action(() =>
{
if(e.NewItems != ...
-3
votes
1answer
34 views
How create unit test the performance of an application? [on hold]
What I want is to run automatically methods to tests the performance of an application. Just like the unit tests, but with the purpose of evaluate the performance and create reports if is it possible.
...
1
vote
2answers
101 views
Implementing a generic/dynamic custom property system in C#
I have an architecture design problem which I think is appropriate for this site.
General problem description:
My primary goal is to design a software library/program (C#) to automate a very ...
3
votes
1answer
61 views
Wpf: Event driven vs MVVM design pattern
I'm a beginning coder and I've been working on a WPF app for several months now and struggled to implement anything in MVVM due to time constraits to learn so I coded my program the only way to knew ...
0
votes
3answers
67 views
BackgroundWorker starting again in Completed event
I want a background worker to continue running and occasionally update the user interface. My first idea was to use a BackgroundWorker and in its completed event just fire it up again.
Is using a ...
0
votes
1answer
79 views
How to verify that library assemblies originate from a given Web site?
How would the following solution be implemented? Would you need to put this code in each library assembly or just in the main assembly that is determining whether it is safe to call the library ...
-3
votes
1answer
172 views
As a new programmer, how do I setup my environment to learn C#? [closed]
I have a little (Grade 12 High School Level) experience with SQL and Java, so my understanding of programming concepts is basic.
I want to learn to code in C# using the .NET framework. I have looked ...
2
votes
2answers
164 views
Having an inherited function return the derived type instead of the base type
I am writing two classes in C#:
A Matrix class that represents a general Matrix with n-by-m dimensions
A SquareMatrix class that inherits from Matrix and has the constraint of being n-by-n
The ...
7
votes
3answers
288 views
What optimizations can be done for soft real-time code in C#?
I'm writing a soft real-time application in C#. Certain tasks, like responding to hardware requests coming in from a network, needs to be finished within a certain amount of milliseconds; however it ...
4
votes
1answer
80 views
Is it better to put an event on the top object or closer to where it's local?
Take the following basic structured code for example:
class Player
{
public QuestLog QuestLog { get; set; }
}
Let us consider that "QuestLog" has the ability to fire off some events when things ...
0
votes
2answers
161 views
C# - initialize variable inside method and use in whole class [closed]
this is a conceptual question, but if i initialize a variable in c# as public will it be able to be used in the class as I want a variable "player1" and a variable "player2" where either could be one ...
1
vote
0answers
96 views
How do I resolve $ref in a JSON object?
I have written a single page application that uses rest services to retrieve JSON objects. The JSON objects being returned are C# objects serialized using the Newtonsoft.JSON library. The returned ...
0
votes
1answer
71 views
Synchronized access to network industrial equipment
I have an industrial equipment which is controlled by a software. The software connects to it using sockets, and keeps the connection all the time alive, while from time to time sending commands to ...
-1
votes
1answer
260 views
Are there any scenarios where the 'Dispose Pattern' shouldn't be used on an Object which contains managed and un-managed resources?
MSDN says that to properly clean up an object which contains managed and un-managed resources, you need to implement the 'Dispose Pattern'.
Given that the class implements the IDisposable interface, ...
5
votes
3answers
401 views
Overloading methods that do logically different things, does this break any major principles?
This is something that's been bugging me for a bit now. In some cases you see code that is a series of overloads, but when you look at the actual implementation you realize they do logically different ...
-1
votes
0answers
79 views
Credit Card Payment Processing which APIs do you use? [closed]
It's for a Point of Sale Terminal where the customer will bring the physical credit card and it will be swiped through the terminal. The business has a merchant account on some banks.
So, how do I ...
7
votes
6answers
511 views
Algorithm to generate N random numbers between A and B which sum up to X
This problem seemed like something which should be solvable with but a few lines of code.
Unfortunately, once I actually started to write the thing, I've realized it's not as simple as it sounds.
...
21
votes
12answers
5k views
Why does void in C mean not void?
In strongly-typed languages like Java and C#, void (or Void) as a return type for a method seem to mean:
This method doesn't return anything. Nothing. No return. You will not receive anything from ...
7
votes
4answers
433 views
Alternatives to multiple inheritance for my architecture (NPCs in a Realtime Strategy game)?
Coding isn't that hard actually. The hard part is to write code that makes sense, is readable and understandable. So I want to get a better developer and create some solid architecture.
So I want to ...
1
vote
3answers
139 views
Am I violating LSP if the condition can be checked?
This base class for some shapes I have in my game looks like this. Some of the shapes can be resized, some of them can not.
private Shape shape;
public virtual void SetSizeOfShape(int ...
2
votes
2answers
149 views
Dependency Injection: where to store dependencies used by only one method?
I am developing a project integrated with Dependency Injection (just for reference, I'm using Unity).
The problem is that I have some Manager classes with several methods and in many cases I have ...
1
vote
0answers
43 views
In WPF, should I base my converters on types or use-cases?
I'm looking for some advice on how to write my WPF value converters. The way I'm currently writing them, they are very specific, like (bool?,bool) => Brush, i.e. I'm writing each converter for a ...
0
votes
1answer
74 views
How to make the members of my Data Access Layer object aware of their siblings
My team currently has a project with a data access object composed like so:
public abstract class DataProvider
{
public CustomerRepository CustomerRepo { get; private set; }
public ...
1
vote
1answer
71 views
Performing a Depth First Search iteratively using async/parallel processing?
Here is a method that does a DFS search and returns a list of all items given a top level item id. How could I modify this to take advantage of parallel processing? Currently, the call to get the sub ...
1
vote
2answers
237 views
C# inherit from a class in a different DLL
I need to make an application that needs to be highly modular and that can easily be expanded with new functionality.
I've thought up a design where I have a main window and a list of actions that ...
0
votes
2answers
119 views
Interface (contract), Generics (universality), and extension methods (ease of use). Is it a right design?
I'm trying to design a simple conversion framework based on these requirements:
All developers should follow a predefined set of rules to convert from the source entity to the target entity
Some ...
1
vote
0answers
93 views
What strategy to follow while matching sql server datatypes in C# Code First approach while using Entity Framework
While matching SQL Server datatypes with C# Code First Approach in Entity Framework, what are specific points that we should keep in mind so that our C# datatype should match exactly our SQL Server ...
2
votes
3answers
201 views
Decoupling software components via naming convention
I'm currently evaluating alternatives to refactor a drivermanagement.
In my multitier architecture I have
Baseclass
DAL.Device //my entity
Interfaces
BL.IDriver //handles the dataprocessing ...
-2
votes
2answers
74 views
How to name a clamp function that only clamps from one side? [closed]
Clamp() is a function that ensures that provided variable is in provided range. You can find such function in .NET, in Unity, and probably anywhere.
While it is useful, I often need to clamp my value ...
2
votes
2answers
162 views
What to Return with Async CRUD methods
While there is a similar question focused on Java, I've been in debates with utilizing Task objects. What's the best way to handle returns on CRUD methods (and similar)?
Common returns we've seen ...
0
votes
0answers
10 views
String contains trailing zeroes when converted from decimal [migrated]
I've run into an unusual quirk in a program I'm writing, and I was trying to figure out if anyone knew the cause. Note that fixing the issue is easy enough. I just can't figure out why it is happening ...
1
vote
1answer
66 views
Where to store front-end data for “object calculator”
I recently have completed a language library that acts as a giant filter for food items, and flows a bit like this :Products -> Recipes -> MenuItems -> Meals and finally, upon submission, ...
1
vote
1answer
207 views
Implementation of instance testing in Java, C++, C#
For curiosity purposes as well as understanding what they entail in a program, I'm curious as to how instance testing (instanceof/is/using dynamic_cast in c++) works. I've tried to google it ...
0
votes
0answers
3 views
Console App error An object reference is required for the non-static field, method, or property [migrated]
Hey all I am trying to get the following code to work but currently I am getting this error:
An object reference is required for the non-static field, method, or
property ...
0
votes
1answer
171 views
How can I set a time limit for a game?
I am learning the multi-threading and timer in C# now. But it seems I can't find a good solution.
For example, I would like to see how many addition problems that I can solve within 1 min. I would ...
0
votes
1answer
93 views
Can't understand on how to implement MVP/MVC for my software requirements [closed]
Recently I decided to start developing a client/service based system using WCF and a Duplex Channel (callbacks from Service to client). The clients will behave as "slaves", that is, they will only ...
1
vote
1answer
36 views
Replaceable parameter syntax meaning
Replaceable parameter syntax for the console object in C#.
I am taking the O'Reilly C# Course 1 and it is asking for a replaceable parameter syntax and it is not very clear on what that means. ...
0
votes
1answer
81 views
Passing in config values to a method using SOLID principles
I have an email helper class that has a method that sends email:
private static class EmailHelper
{
public static void SendEmail(string from, string to, string subject, string message)
{
...
-2
votes
1answer
70 views
How to interrupt ongoing transaction with cancel request explicitly from UI? [closed]
I want to implement one transaction which will take at least 10 seconds to complete the process.
Meanwhile user has an option to cancel on going process. I have to stop the transaction without ...
-2
votes
1answer
56 views
How to get a database on my filesystem that I can use in my application [closed]
I'm making a .NET application where I'll have a lot of data entries. This will not go to any server though, but needs to be stored and updated, frequently on the local machine.
I would like something ...
0
votes
1answer
194 views
There's a most performant way to check that a collection has exactly 1 element?
I came up with this solution :
if (Take(2).Count() == 1)
is there any more performance solution (or better syntactical sugar) to do this check ?
I want a performance way because this will be an ...
36
votes
7answers
4k views
Why do people nowadays use factory classes so often? [closed]
I've seen the history of several С#/Java class library projects on GitHub and CodePlex, and it seems like a trend.
Why do people nowadays use factory classes so often for almost everything? I.e. We ...
13
votes
1answer
1k views
Why were magic methods implemented in C#?
In C#, I started seeing all these magic methods popping up, without being backed up by an interface. Why did Anders Hejlsbjerg (or whoever is in charge for C# development right now) choose this?
Let ...
0
votes
0answers
4 views
how to send mail using Exchange server through proxy server [migrated]
MailMessage mail = new MailMessage();
mail.To.Add("**");
mail.CC.Add("*");
mail.From = new MailAddress("*");
mail.Subject = "Salesforce Credential for ...
4
votes
2answers
107 views
Entity Framework with no direct table access
There are some similar questions I've found here, but none of them fully answer the question I'm asking. Similar questions: here and here
In my company, I develop C# .NET applications and our Server ...
1
vote
3answers
182 views
Make Return Type an Interface - Problem with Initialization
I would like to make the return type of my method an interface rather than a class for similar reasons stated in c# List or IList, however I am having trouble figuring out how to initialize the ...