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

3
votes
2answers
292 views

Why aren't all method virtual or why doesn't have each class at least one interface?

This is more philosophical question, which address .NET platform, but maybe it is useful also for other languages. I'm doing lot of Unit Testing and especially when I'm using third-party components I ...
0
votes
0answers
47 views

Serializing .NET object into a JSON string produces unreadable output [migrated]

I'm trying to convert a .NET object into a JSON string, because I want to be able to read the content of this object in the client side. Here is my controller code: public ActionResult ...
1
vote
2answers
105 views

Design pattern for managing three different objects

I´m looking for the best way to solve following problem: I have three lists of different objects: AppleJuice, OrangeJuice & Juice. All Juice properties exists in AppleJuice & OrangeJuice ...
7
votes
3answers
1k views

Foreach loop and variable initialization

Is there a difference between these two versions of code? foreach (var thing in things) { int i = thing.number; // code using 'i' // pay no attention to the uselessness of 'i' } int ...
3
votes
1answer
70 views

Dependency Inversion expands the API, results in unnecessary tests

This question has bothered me for a few days, and it feels like several practices contradict each other. Example public class FooDao : IFooDao { private IFooConnection fooConnection; private ...
1
vote
1answer
94 views

Got confused while designing Aggregates

I am designing an application, which will store sports statistics, show them in different diagrams and do few more operations on them. Allow user to do some mock drafts etc. I choose to build a ...
8
votes
2answers
205 views

Is it bad to create classes whose sole purpose is to be converted to another class implicitly?

Imagine a situation where we're using a library that allows you to create Circle objects, where you can specify the radius and the center of the circle to define it. However, for some reason, it also ...
2
votes
2answers
99 views

Standard way to call virtual method

So recently I was working on a project where I had a base class that provided some common functionality. It had several virtual (overridable in vb) functions. I noticed that some of these methods ...
-2
votes
0answers
78 views

How to add and use a database in a C# project in Visual Studio 2015? [migrated]

I'm learning C# for about 7 months now, and currently I'm studying LINQ. I worked with local collections, but I'd like to use it with databases too, and learn how to use a database in a program. The ...
0
votes
1answer
91 views

How can I avoid duplicating information in this scenario?

I have a Data class that can be placed inside a DataCollection class that can be placed inside a DataCollectionCollection class. Kinda like an egg can placed inside a box that can be placed inside a ...
0
votes
1answer
443 views

Address search from large text file

Basically I want to develop a Address lookup(part of my project) using C# (and I can use SQL if necessary). I have a very large text file which have all the UK address and postcodes. Addresses needs ...
0
votes
1answer
40 views

How to calculate new property for old records efficiently?

Let's say we have classes something like this: public class Item1{ public Guid Id {get; set;} public string Name {get; set;} public decimal Price {get; set;} public int Quantity {get; ...
1
vote
1answer
53 views

Knowledge base UI pattern

In our database backed (C# WPF / Entity Framework) application, we want to build a system to enter, store, display and search arbitrary content linked to our main entity. The challenge here is to find ...
1
vote
2answers
69 views

Validating transaction codes with reference codes… Best way to encode the validation rules?

I have a series of reference codes that my end users create during the course of the day. These reference codes correspond to a transaction code that is stored in a database. As of now, there are 15 ...
3
votes
3answers
110 views

Ambient dependency injection through static service locator

After some googling I found some debates about whether constructor injection or property/field injection is better, but there is yet another alternative that strikes me as more beneficial. In most ...
0
votes
2answers
453 views

Finding lowest cost path - dynamic

I have to write a dynamic algorithm for finding lowest cost path. So I have a point that I have to visit. I can jump only between points by distance - 5 I have an array of distance from 0-point for ...
-1
votes
0answers
26 views

Text script to .net code [on hold]

I have a set of text files which contain the keywords. I need to generate C# code / C# classes by reading these files using C#. Each text file is meant for a class. The keywords map to methods in the ...
2
votes
1answer
381 views

How to backup data and images in this project? [closed]

I have MS C# and MS SQL 2008 database project. It can capture employees' records with pictures of more than 1000 records. Presently, I'm able to capture say 150 records on PC1 using my installed C# ...
2
votes
1answer
156 views

Why and when would you use a .NET framework data type?

I've seen an increasing trend of people submitting code to SO that includes the use of .NET Framework data types. I understand that the .NET Framework has its own data types (like Int16, Int32, ...
1
vote
1answer
113 views

What is the correct reusable architecture using Entity Framework for common database tables and services?

Context I have a line of business application "MyApp" in C# using EF. Layers are separated as MyResusableLib.DataAccess // Class Lib: EF based utils, extension methods, MyApp.DataAccess // Class ...
3
votes
5answers
120 views

Conditionally initializing a string list

I am writing a program that needs to be able to process data from a number of different sources. The sources output data in a variety of formats. So, depending on which source is being used, I need to ...
-2
votes
0answers
33 views

understand and use Event , personal event example [on hold]

i m in front of first uses of personal event. I present some of my doubts and my problems.. I write a small class CountDown, is use a timer to create a countdown and raise an event when time target ...
1
vote
1answer
84 views

Is a PropertyChanged event handler bad if it is used for updating the database?

I have a class with several fields. public bool Active { get; set; } public List<Group> Groups { get; set; } public string FirstName { ...
3
votes
1answer
108 views

Create different classes for staffers and users?

I am building a program for a law firm. When a staffer is active (i.e. still works at the firm) he has a password to login the program; When a staffer is inactive (i.e. no longer works at the firm) ...
-4
votes
0answers
33 views

Mysql connection is failed to login [on hold]

I have installed mysql workbench 6.3 CE and created database and one table and try to get data from window form application. Following is code for connectivity: String Conn = "Data Source = ...
2
votes
1answer
110 views

Onion architecture design question

I recentlly started working on a new project where the team was considering use onion architecture, which I was not very familiar with, so I started reading about it. The application is a simple 3D ...
1
vote
4answers
259 views

How to mark/track features in code?

After some time in every project sooner or later you will need to find a feature in it a fix it or extend it so I was wondering if there is already a system or a convention for marking those features ...
4
votes
3answers
2k views

Separation of retrieving data and business objects between DAL and BLL Layers

I did some research before posting this question. Among other questions or post, one of those is provided below. I could not get a clear mind how to determine.. Business Objects within a Data Access ...
-5
votes
0answers
34 views

Make VS copy and paste code using some kind of attribute [migrated]

I am using VS 2015 and C# I tried to search for it but I don't know what terms to use... What I want to do is to mark part of my code with compiler special attribute or something and then go to ...
5
votes
1answer
219 views

Why does this shared buffer work?

Background The following code snippet is taken from a problem in, Visual C# 2005: How to Program, by Paul and Harvey Deitel (pp. 735). The code snippet is more or less an application for accessing ...
7
votes
5answers
200 views

Open Closed principle in design patterns

I am bit confused about how Open Closed principle can be applied in real life. Requirement in any business changes over the time. According to Open-Closed principle you should extend the class instead ...
0
votes
0answers
34 views

Suggestions for dataloading - semi dynamic data

I have a very old Perl based system that is used for CAD drawing searches, where each drawing has many metadata fields associated with it. Currently, the 'old' system has a database schema that has ...
2
votes
0answers
171 views

Dictionary of dictionaries design in C#

My question: is there a canonical way of creating a dictionary of dictionaries and providing an outer/inner key pair? Is there a NugetPackage out there with an implementation? In my code, I have now ...
13
votes
7answers
1k views

Does C# experience translate well to C++? [closed]

My programming classes in school were C++, but I ended up working a job doing C# for the last few years. If there was a position that required say 1 or 2 years experience in C++, would my experience ...
4
votes
1answer
261 views

Managing resource paths in source code

I suspect this is something that many of you have dealt with, and I'm certain there's articles on how to do it, but I can't seem to find them. My problem is that my various constant classes in Java ...
11
votes
5answers
334 views

Is indiscriminately catching exceptions (Pokemon exception handling) ever acceptable? [duplicate]

Normally, I don't anticipate exceptions and if I get them, its something that I can't fix in my code - bad user input or connectivity issues with the database. But errors do occur so at the very ...
5
votes
4answers
194 views

Does anyone have a good DI registration pattern?

I've done this so many times but I never end up liking how my code turns out. I'm asking if anyone else has the same problems and can offer solutions or conventions that they've used to make cleaner ...
0
votes
1answer
94 views

Recommended approach to initialize Command

I've two commands in my View Model and one of them is initialized using lazy loading and other using eager loading. Which approach is good to go? Should I use lazy loading or eager for both? View ...
0
votes
0answers
11 views

Default Application Compatibilty Manifest for new Visual-Studio projects? [migrated]

I'm currently fighting with some app compat settings, specifically a certain shim, and looking into the compatibilty section of the application manifest. Details aside, one thing that strikes me as ...
-4
votes
2answers
77 views

Referencing a C++ DLL from within a C# ASP.NET project using Visual Studio Community 2015 [closed]

This question might be a little odd, but is there any specific way to import a C++ reference into an ASP.NET C# project? The problem I am having is that VS is giving me the following error: ...
-2
votes
2answers
173 views

OOP project design

here is the UML class diagram subscribe method is used to add a herbivore object to the plant's watchers. when a plant is told to notify, itloops through all of the herbivore object in its watchers ...
1
vote
1answer
105 views

Using ninject in a class library

Looking for some help getting my head around ninject and DI. Using the simple examples I've found online everything works nicely but trying to do something more complex is causing headaches. I have ...
0
votes
1answer
161 views

Is there an easier way to do this with Lazy<T>?

I was trying to find a concrete example online but I couldn't find one that also used one of the class' other attributes. So, can this be done more succinctly with a Lazy<T> object? public ...
2
votes
2answers
83 views

What is the best approach to update a database field when a corresponding class property changes?

I have a class with several fields. public readonly byte Id; public bool Active { get; set; } public List<Group> Groups { get; set; } public ...
5
votes
2answers
121 views

Recreating complex aggregates from a persistance source

I'm building a web application with C#, and I have an aggregate root which has several entities and value objects. Then I have a repository object which persists the aggregate to the database (I'm ...
1
vote
4answers
9k views

How to Console.WriteLine from [TestMethod]?

I am trying to show some information from a [TestMethod] method. Usually we use NUnit and a line with Console.WriteLine runs fine and we can see it in 'output' window, but on this project we must to ...
-3
votes
2answers
160 views

Can a media decoder/player be implemented entirely in C#? [closed]

One of these days, when talking to a friend about different programming languages and their uses, I mentioned that video players (and media coding implementations) are always written in lower-level ...
2
votes
4answers
146 views

Unit Test for Void which copies data from one location to another

Still learning and getting my head around Unit Testing, (also trying to get into TDD, though I appreciate it isn't the same thing) and in many ways it is changing/improving my code. But I come across ...
4
votes
2answers
192 views

Name for a Chainable ForEach [closed]

Linq has a method Select, which takes a Func<TIn, TOut> and maps it over an iterable. I'm trying to come up with a good name for a method that takes an Action <TIn>, transforms it to ...
1
vote
1answer
58 views

Asynchronous client-server implementation

The mission: Implement a program that will listen to multiple client requests asynchronously (on TCP) and transfer them to a server (also on TCP) to which only one connection is allowed. The program ...