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
1answer
101 views

Session states in ajax callback

Someone told me Session or HttpContext.Current.User will return different value when we are working with ajax postback, in case of when the are so many user are live to site. For example, suppose ...
2
votes
0answers
134 views

An efficient way of starting an arbitrary number of consumer threads?

I have a Producer/Consumer implementation where the number of consumers is configurable (this is a form of configurable throttling). The producer and consumer are kicked off like this: var cts = new ...
9
votes
2answers
435 views

Why is there a new() constraint in C# but no other similar constraint?

In C# generics, we can declare a constraint for a type parameter T to have a default constructor, by saying where T : new(). However, no other kinds of constraints like this are valid - new(string) ...
0
votes
1answer
166 views

Application use on website

Is there a good way to run a C# application on clientside in lieu of JavaScript? I have done some front end work with JavaScript and backend C# for web developing at an old job, but I am interested in ...
1
vote
1answer
305 views

Most Appropriate Authentication Type for MVC5 project

I am about to start a new ASP.NET MVC5 project and I am planning the authentication / authorization requirements at present. The client wants Windows authentication, to prevent their users having to ...
0
votes
1answer
87 views

Natural Language to Search Criteria - Date Ranges

Consider an application that stores a set of records that contain: Description Cost Purchase Date I'd like to be able to allow users to utilize natural language to search the dataset. For ...
0
votes
1answer
108 views

Generic object construction - Inherited Classes

Basically I am writing a MSMQ based multi-threaded messaging pattern utility library. It's like a set of components all inherited (directly or indirectly) one class that's called my base component ...
0
votes
2answers
172 views

How to go about saving a Snippet / Block of Code [duplicate]

I am currently learning C#, I am pretty proficient in Java. A project I have been working on for a while is basically an application that lets you input code "Snippets" or blocks of frequently used ...
9
votes
4answers
240 views

Purposely raising exceptions to use catch

For a typical if...else wrapped with exception handling, is something like the following example a recommended practice to avoid code duplication? try { if (GetDataFromServer()) { ...
0
votes
0answers
51 views

Creating New Wrapper Objects and Extension Classes and Keeping it Organized

Here's my situation: I'm programming an embedded device with a very simple, but customizable LED array display. It's 10 RGB LEDs linearly setup. The LEDs will be used to display many different ...
2
votes
1answer
100 views

Accessing a private array when I have an extension method

I'm trying to make a number of data classes for my C#/XNA game, which would essentially be a wrapper around T[,]: public interface IGrid<T> where T : struct { Point Size { get; } T ...
0
votes
1answer
91 views

Advise on loose coupling between user controls

I have 5 user controls on the page and each control implements it's own interface that contains properties and events. In order to enable communication between user controls, I am creating a property ...
6
votes
6answers
1k views

Would a “downcast if block” be a reasonable language feature?

Consider the following "if cast": class A { public void f1() { ... } } class B : A { public void f2() { ... } } A a = foo(); // might return A or B if ( a is B ) { // Inside block, ...
2
votes
2answers
213 views

Is there a point in using closures for non-fully functional programming languages? [duplicate]

Maybe I don't understand closures fully but take for example C#, why would I use closures when I can use classes? Am I missing something? Note that I read this one already but my question is specific ...
1
vote
3answers
147 views

Relative encapsulation design

Let's say I am doing a 2D application with the following design: There is the Level object that manages the world, and there are world objects which are entities inside the Level object. A world ...
2
votes
3answers
460 views

Typical instantiation of new object - is there a way to avoid repetitious syntax?

When learning C# (and OO concepts more generally at the same time) something I found very distracting is exemplified by the following line: ExampleClass exampleObject = new ExampleClass(); It's the ...
0
votes
0answers
262 views

How to design socks proxy server (OOP)

I'm working on a socks server application written in C#. But I don't really know how to design this in a nice way. I got this for Socks V4 and V4A: I'm not sure if it clears things up, but I think ...
2
votes
1answer
91 views

how to process document state transition?

Imagine there is an application (ASP.NET MVC) that processes some documents. The document must be revised several times by different group of users. state/role rules: simple user can only publish ...
-1
votes
1answer
214 views

How to make C# methods work like javascript functions? [closed]

I'll keep it simple, I want to make C#'s methods work like javascript's functions. Mainly so I can convert this - function makeVariable(terp) { var me = {value: 0}; return function () { ...
1
vote
1answer
189 views

alternate approach of binary serialization/de-serialization

Is it possible to convert a list of object directly to byte[] (and vice versa) to gain performance (by avoiding serialization/de-serialization)? What I have in mind is that a list is somewhere in ...
0
votes
4answers
319 views

How to design an IDisposable that unconditionally needs to be disposed?

Consider a class that implements IDisposable, and that has members in such a way that it will never become eligible for garbage collection when it is not disposed. And as it will not be garbage ...
-1
votes
1answer
91 views

assembly.GetTypes() vs assembly.DefinedTypes.Select(t => t.AsType());

public static IEnumerable<Type> GetAccessibleTypes(this Assembly assembly) { try { #if NET40 return assembly.GetTypes(); #else return ...
0
votes
0answers
40 views

Sproc chaining verse discrete calls from OO code

I'm currently working on a change at work to generalize a function that was sloppily coded up to work for a particular use case. The function calls a particular sproc that checks if an entity exists ...
-1
votes
2answers
183 views

Word recognition in a string without spaces or punctuation marks

I have a small C# project that reads a file and gives me an output: a string that does not contain spaces nor any types of punctuation marks. It may also contain a few misspellings. Ex. Output: ...
1
vote
1answer
148 views

Are there any valid uses for the System.Collections.Specialized classes any more?

Are there any valid uses for the classes in the System.Collections.Specialized namespace any more or are they all superseded by the classes in the System.Collections.Generic, ...
0
votes
1answer
274 views

Are VB.NET and C#.NET projects created from Microsoft Visual Studio “Open Source” safe? [closed]

I'm developing software in VB.NET and C#.NET and planning to release their source codes as fully open source. Are these projects "open-source" safe? My doubts are: VB.NET and C#.NET are using the ...
1
vote
1answer
161 views

Should I use inheritance or an interface?

So in a nutshell I have an abstract class : public abstract class Member { public string PCode { get; set; } public string Reference { get; set; } public DateTime? ElectedDate { get; set; } } And ...
1
vote
2answers
206 views

Testing C# Eventhandler Subscription

I want my unit tests to be able to verify that some events were subscribed or unsubscribed at specific points. Currently, I see two options. VerifiableEventHandler Each client subscribes using the ...
1
vote
1answer
175 views

Best practice for projects architecture - server side [closed]

The usual way (that I'm familiar with) to divide the server side is the n-layer architecture : DAL - data access layer, usually has the Entities and the context (and maybe include also a repository) ...
1
vote
1answer
255 views

How can I create a set of random numbers based on a total and number of objects?

For example with: Total population = 400000 Number of villages = 800 The average population is 500 How can I randomize the amount of people in each village using a specified deviation (eg +-50) so ...
0
votes
1answer
225 views

The problem of dependencies management

Let's consider the next situation: We have a module A which has a class Crt570 intended to interact with a device. We have a module B which uses Crt570 in the class called M100Communicator. We have ...
0
votes
1answer
118 views

A specific problem with architecturing a part of our application

Firstly, I'll try to describe the real world model of what we are trying to express in C# code. We have a device called M100. It's purpose is to read\write data from\into cards (plastic or ULTRALIGHT ...
0
votes
1answer
114 views

Executing user configuration settings

For an API I'm building what it does is load an XML file that is passed to it as a string, drill to the correct element, modify values, and return the modified XML. I'm doing something like this in ...
1
vote
2answers
195 views

Environment-aware Code

There are situations where the deployed environment (development, test, or production, for example) might dictate the outcome of certain actions. For example, perhaps a successful "user registration" ...
0
votes
1answer
181 views

Export to Excel - threading

I am working on an ASP.NET application. One requirement by the users is they are capable of exporting to Excel of some UIs. I have worked on them using the Infragistics library, and I have supplied ...
0
votes
3answers
258 views

Storing a C# dictionary of type <datetime,enum> [closed]

As title says it, i'm looking for a way to store many dictionaries (one per user) of type Dictionary<DateTime,enum> in a database (sql server 2012). Each dictionary has 366 items inside and it ...
1
vote
3answers
219 views

Gathering IP address and workstation information; does it belong in a state class?

I'm writing an enterprisey utility that collects exception information and writes to the Windows Event Log, sends an email, etc. This utility class will be used by all applications in the corporation: ...
1
vote
1answer
201 views

Does the recent open sourcing of MSFT's C# compiler mean it can be made cross-platform? [closed]

I really enjoy working with C# however one of its biggest drawbacks is that it is kind of split-brained between MSFT .NET and Mono. In practice its not a big deal most of the time but it is one of ...
0
votes
7answers
764 views

Is there any performance benefit in checking the item count prior to executing a foreach loop?

I saw this in code and was wondering if there is any performance benefit to checking the item count prior to looping: if (SqlParams.Count > 0) foreach (var prm in SqlParams) ...
9
votes
2answers
389 views

Compile-time IOC

Has anyone started a project to do IOC at compile time (possibly using Roslyn or Linq MethodInfo emit)? My experience with IOC containers has thus far been great, baring a few small issues Many IOC ...
0
votes
2answers
190 views

How To Invoke A Method When It's Class is Accessed (Any Method) - “OnClassEnter”

I am working on a C# net micro framework project, in particular an I2C bus management/class. I have several different I2C devices each defined in separate classes which contain all of the devices' ...
1
vote
1answer
226 views

Organising data access for dependency injection

In our company we have a relatively long history of database backed applications, but have only just begun experimenting with dependency injection. I am looking for advice about how to convert our ...
0
votes
3answers
381 views

What is the main goal of MVVM pattern? [closed]

Could you tell me what is the goal of the MVVM pattern? What are the arguments or the reasons I can give to a team and product owner to respect and develop according to this pattern? I would like a ...
0
votes
1answer
265 views

ASP.net performance code behind vs app_code

I am wondering about performance of a web site/application when there is code in the code behind files rather than when the code is moved to separate files in the App_Code folder. My understanding ...
1
vote
2answers
414 views

Testing ASP.NET .aspx and .ascx code behind files

I am wondering how to test .aspx.cs and .ascx.cs code behind. Can I use unit testing and if so how? Are there alternatives that will help test the functions in the code behind files? I don't know how ...
1
vote
1answer
175 views

How to get back into software development when you took a 10yr break? [duplicate]

I graduated 2004 CECS and the only experienced I had was at intern for 2 years. At that time I had c and c++ knowledge. I took a 10yrs break and now want to go back into it. I am interested in c#. ...
0
votes
1answer
382 views

Domain driven design and WCF services architecture

I am trying to figure out how to architecture my project in the DDD paradigm (a complete beginner in DDD) and stumbled upon a problem about the implementation of the web services... These are some ...
0
votes
2answers
75 views

Container/Item pattern without `friend`

I have a class Container containing objects of type Item. They are different classes, and especially they have no common base class (e.g. a Container does not itself have a Container).: class ...
1
vote
0answers
117 views

How much segregation is too much in this design?

We are working on ASP.NET webforms application developed using WCSF (MVP pattern). In the application, there is a search screen that allows the user to enter some fields and display the results. We ...
-3
votes
1answer
46 views

Text field Form [closed]

I have 2 forms that have text input fields. One is written in JavaScript and the other in ASP NET. I would like to prevent a single symbol, the dollar or string "$" symbol from being entered into the ...