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

1
vote
2answers
49 views

Is there any reason to write delegates/events for one class?

I have a game with such events as GameOver, GameStart, PlayerWin, etc. I only have one class that is listening on these events, for the purpose of sending these events as TCP json messages to a client ...
1
vote
1answer
32 views

Class structure for Entity Framework

I'm using EF (Code first) and I'd like to isolate the properties from the methods (many of the methods reference other libraries that I don't want my database project to have to reference). As an ...
0
votes
1answer
50 views

Best way to deliver new version(updates) to users of small client-server .net desktop application

I am developing small app for my client from different continent. Client will continuously request new functionality and new version will be delivered every 2 month. As I do not include some auto ...
0
votes
1answer
61 views

Is it good practice to assign an instantiated class to a static property in the same class?

I have code that was written by someone else that goes like this: On a ViewModel: public static ACertainViewModel Default { get; private set; } On the same ViewModel's constructor: public ...
-1
votes
2answers
46 views

Integer conversion with Console.ReadLine()

To read a integer form keyboard I will use: int number = Convert.ToInt32(Console.ReadLine()); But why won't this work? int number = (int) Console.ReadLine();
0
votes
3answers
101 views

C# — Is there a key/key lookup table type provided in .NET?

It seems like a pretty straightforward thing to add, but I just want to be sure .NET doesn't already provide one and save me from adding unnecessary code: I need a lookup table (like a Dictionary) ...
1
vote
2answers
70 views

How do I write a proper messaging protocol?

I need to write a messaging protocol between client and server for a game application. I need to send messages back and forth such as, Player joined a game, player left game, player performed this ...
5
votes
3answers
140 views

Should I make my own exceptions, or co-opt similar exceptions for slightly non-standard purposes?

This is a general design question, but I'm focusing on C# and .NET because those are the languages I'm working with right now. Should I create my own, new exception classes, or co-opt existing ...
1
vote
1answer
127 views

C# Refactoring Code OOD and SOLID

I’m having some questions regarding improvement of code structure and maintainability, especially regarding SOLID. These questions are specifically for this project, so I would be happy if this ...
-2
votes
0answers
12 views

Problem with C# File IO in Winforms [migrated]

I'm having issues with a C# Winforms file IO. The code complies just fine, but then it returns errors on execution. The output code is here: private void saveData() { string fullPath = ...
1
vote
4answers
202 views

What if the “catch” block is empty - “{}”

Is it proper to use below syntax for try catch?? try { int a; int b; int c=a+b; } catch (exception ex) { //Nothing here }
2
votes
6answers
656 views

Replacing C with JavaScript as an introductory programming language [on hold]

I am a new teacher at polytechnic where we teach web development and basic software programming. For years, the institution where I teach have taught C as their introductory programming language to ...
1
vote
3answers
149 views

Advantage of generic base class [on hold]

What's the advantage of having a generic base class and a derived class having itself as the generic parameter on the base class. e.g. public abstract class MyBase<T> {} public MyDerived : ...
0
votes
0answers
32 views

Emulating `tail` to stream log data via asp.net mvc

In similar fashion to this bit of node.js, I'm interested in streaming the ongoing output of a text log file via ASP.NET MVC. I'm having trouble even thinking how I would implement this using the ...
1
vote
1answer
82 views

Accepted Patterns For Base Class with both Static And User-Defined Data Sources

I have a requirement to build a 'base' profile library (in C# - NET 4.5.2) for various different internal (technical) consumers. This profile consists of metadata fields that would be shared by a ...
-5
votes
0answers
40 views

Windows custom lockscreen program [closed]

I'd like to create a windows application that locks my screen, I want the program to have the same functionality as this program but I want to add functionality to it so I can play custom sounds and ...
0
votes
1answer
64 views

Extensions on Visual Studio 2015 Express [closed]

I used to install some extensions on VS Express 2013. We were using it to create some internal tools, one of them was Web Essentials. I wanted to start using VS Express 2015 so I could use the new C# ...
4
votes
3answers
249 views

How can I add properties to subclasses and access them without casting from a superclass?

I'm trying to model a multi-dimensional point class in C#. I have about eight different types of points, and there may be more in the future. Right now, I have a superclass (PointBase) that holds all ...
4
votes
1answer
121 views

Dependency Management in the real world?

Most of the examples i've see when watching anything on dependency management hit what i consider to be the holy grail in that the only dependencies on classes are interfaces that the IOC container ...
2
votes
0answers
73 views

How do I test with multiple input combinations?

I have a piece of code that I need to test, which is layered in three parts: Web API Controller Persistence/Logic Layer System calls for persistence It's the basic GET/POST/PUT/DELETE call system. ...
22
votes
3answers
2k views

Class with members that are mutable during creation but immutable afterwards

I have an algorithm which creates a collection of objects. These objects are mutable during creation, since they start out with very little, but then they are populated with data in different places ...
15
votes
4answers
2k views

Why does C# have both out and ref?

C# has the out and ref keywords. Why are these two required? Disclaimer: I don't have deep knowledge of C#.
1
vote
1answer
158 views

Could there be a use case for C# style auto-properties in Python

I've been doing a lot of work in C# recently (my primary language is Python) and I love that I can do something like public string MyProperty{ get; set; } Going back to Python I miss that sort of ...
-1
votes
0answers
4 views

(C#) sending hex over serial [migrated]

So I'm trying to send a (string?) of hex that looks like this "7E 00 00 FF 00 00 00 00 00 00 00 00 00 00 00 00 00 FF" over a serial port. My code looks like this: serialport.write("7E 00 00 FF 00 00 ...
0
votes
2answers
82 views

How can I show and hide a single field across my web application through a checked value?

Let's say I have a field called "FooName" and I have "FooName" in several places across my web application (ASP.NET MVC4). I have a check box that allows me to turn "FooName" on and off across the ...
4
votes
2answers
70 views

Need sorting method for coordinated, flattenned collection

I have a component which outputs an ICollection of the following type: public class CoordinatedInjectableValue { public int XOffset { get; set; } public int YOffset { get; set; } public ...
0
votes
3answers
321 views

i++ vs i+=1 in cycles, why evaluate? [closed]

Why do most programmers use i++ in cycles? Doesn't it mean evaluate and increment. I find more logical to use just an increment i+=1, because that's all I want. WriteLn(i++); would evaluate i and ...
0
votes
0answers
38 views

SignalR UI updates and group managing

I'm working on a web application and I have 2 specific questions regarding SignalR I need give the UI real-time updates (both broadcast to everybody on the hub, but also just to the original caller) ...
-1
votes
0answers
64 views

Why does internal instance become null [migrated]

I am trying to figure out why the assigner (myC.myself) become null after the line is compiled? Thanks in advance. namespace AequalsBequalsC { class Program { static void Main(string[] args) ...
0
votes
0answers
14 views

Integrating legacy application with new functionality

We have a legacy application with, among other things, the ability to create instances classes within VB6 DLLs dynamically and call methods with varying signatures. We have no way of accessing the ...
21
votes
4answers
4k views

How do I handle setters on immutable fields?

I have a class with two readonly int fields. They are exposed as properties: public class Thing { private readonly int _foo, _bar; /// <summary> I AM IMMUTABLE. </summary> ...
1
vote
3answers
143 views

Design pattern for different code behaviors according to different clients

At my company, we have a solution composed of a WinForm (multiple per client) and an API (one per client). This solution is deployed on different clients that require the solution to behave ...
2
votes
1answer
65 views

Is there a standard way to handle assigning and managing tasks for users/groups in asp.net? [on hold]

Take for example what I would assume to be a fairly standard process flow, where certain users are assigned a role which allows them to create requests, but another group (or subset) are assigned a ...
4
votes
2answers
124 views

Entity Framework Domain Object as Business Object

If I am not concerned with unit testing and switching my data access out at a later time, would using my entity framework objects as my business objects be okay? I have an existing database for which ...
1
vote
1answer
33 views

How to model table and column objects and their relation

I'm working on a small application where I need to model tables and columns from a relational DB. I've been reading some material on nested classes, which is recommended to be used sparsely. However ...
4
votes
4answers
120 views

Instantiating class that contains methods to check some of the settings and also return values from my app.config file

I am writing a console application and have a class called ApplicationConfiguration that contains methods to check some of the settings and also return values from my app.config file. For instance ...
0
votes
0answers
76 views

Any “Gotchas” to using Entity Framework for Identity & Dapper for all other DB access in a .NET MVC application?

I'm firing up an MVC project in which I'd really like to use Dapper as my ORM, as I like to be as close to the database as possible for performance and SQL tweaking reasons, yet still have the power ...
3
votes
1answer
91 views

Best practice for buffering when posting to a web-service that has gone offline

If I am collecting data that needs to be posted to a web service on a regular (~5 minutes) basis, and that service has temporarily gone offline, what is the best practice to ensure we don't lose any ...
4
votes
1answer
161 views

Control Start Of Program

I made a program, which was supposed to run every night as a windows scheduled task, let's say the program is just one method, called Do_Task(). Usually you need to press a button to run the Do_Task() ...
1
vote
1answer
39 views

How to model a time-based m-to-n relationship in Entity Framework using code first

I have to model and manage a time-based configuration. Typically - without an OR mapper - I would start with the database tables. Screen Color ColorScreenMapping ------------- ...
-1
votes
0answers
23 views

Multiple publishers to one subscriber: handling subscribing and unsubscribing [migrated]

I hope this isn't too general, so I apologize in advance if so. I am creating a console text adventure game. I essentially have many monsters, one per room at the moment. I also have a God ...
1
vote
2answers
146 views

Convert this abstract class to an interface

I have a security method I would like to be able to sprinkle into other classes throughout my program. It is currently an abstract class but I feel it would be more appropriate as an interface. Can ...
5
votes
1answer
110 views

Hot-patching a server: dynamically loading types from an uploaded assembly

In the current project I'm working on, some of the C# classes are being stored as source code in SQL Server database records, and executed as needed using CSScript. This is being done so that the ...
2
votes
2answers
66 views

Authenticate in the Services? Or in an Endpoint that exposes the Services?

When I'm in charge, I typically model services separate from endpoints. For example: Company.Project.Domain.dll has all of the logic required to complete the services for that domain. In order to ...
-4
votes
1answer
67 views

Text adventure: how to incorporate pet system which allows pet to hunt? [closed]

The question I have is on how to best implement a feature. Currently I am creating a console text adventure game. It's a project I've been working on for a while now, and due to it being my first C# ...
0
votes
1answer
57 views

Issues deciding on approach to create object

I'm trying to decide what's the best approach to instantiate a particular class. Basically there are two use cases for it: instantiate it in order to save a new entry to the database and fetch an ...
4
votes
3answers
1k views

Is the question “What is the using statement” a bad question to ask an interviewee? [closed]

We're looking to hire a new junior C# developer. We're not looking for guru's or anything, so my boss asked me to write down a few questions and answers of varying difficulty to assess their skills. ...
1
vote
2answers
248 views

Is there a name for this pattern?

A while loop can be written as follows in C# (and many other languages): int someValue; int someTerminatingValue; while ((someValue = GetSomeValue()) != someTerminatingValue) { // Do something ...
1
vote
1answer
46 views

What are the differences regarding speed and functionality between using Actions vs Delegates?

I know this is a language specific question and may not be suitable here but I would like to create an array of functions that will be called based on their index and I would like to know the ...
1
vote
0answers
42 views

How to write class libraries that work with DB

I have programmed a library in C#, which process some EDI into meaningful data based on the DB structure of a table. I have used a typed dataset in the class library project. Now I run into an issue ...