Questions tagged [c#]

C# is a multi-paradigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform. Use this tag for questions related to C#. In case a specific version of the framework is used, you could also include that tag; for instance .net-2.0.

Filter by
Sorted by
Tagged with
6
votes
2answers
13k views

Asynchronous Sockets

I need to implement a TCP client application. The client and the server send messages to each other. I want to make this program scalable enough to handle connections to multiple servers at the same ...
9
votes
4answers
2k views

Is catching 'expected' exceptions that bad?

I had to find the corresponding process for a windows service the other day, and I kept on getting this one exception. I've spent some time researching the exception only to find that this exception ...
4
votes
4answers
478 views

Comment formatter

...
14
votes
2answers
1k views

“Pluggable” routes in ASP.NET MVC

How do I handle multi-tenancy with routes in ASP.NET MVC? The application is a multitenant ASP.NET MVC 3 application. Tenants are identified based on hostname so this does not interfere with routing. ...
4
votes
1answer
748 views

IMapDocument in a 10.1 SOE

I am wondering if this code will work in 10.1. This video at 1:02 says not to create mxd based services. I think that just means not using IMapServerObjects3, but seems like IMapDocument should be OK....
9
votes
2answers
3k views

Async Task implementation

Beeing on .NET 3.5 i don't have access to the TPL. Yet i have become fed up of having to manage manually the logic behind delegate.BeginInvoke type of scenarios each time and i set up to implement my ...
12
votes
5answers
1k views

To make a calculator from scratch

As a personal challenge, I am trying to make a very basic calculator without using any CLR's integer and arithmetic operations, but to only use memory. The idea was to do what CLR/OS does. i came up ...
4
votes
2answers
1k views

TextWriterTraceListener class

I need to extend the default TextWriterTraceListener class to include timestamps with each message on same line and file rotation. I can't seem to find any way of ...
7
votes
2answers
2k views

Slow-running File parser

I've got a method that parses a file. I take all the words and add them to a SortedSet. Every word contains a list of Lines ...
5
votes
4answers
3k views

Is this architecture overly complex or following best practices?

I work as a C# developer at a company that doesn't use best practices at all. We're on .NET 3.5 but most code is written in a .NET 1.1 style (e.g. almost all the logic is in the code behind of the ...
3
votes
2answers
468 views

Open database and hande errors

How to make this code better? ...
5
votes
1answer
1k views

Return Dictionary object having key/value pair of keywords and URLs

Can you please help me split this method to reuse the repeating code? Any advice/comments on the code are welcome. ...
5
votes
1answer
5k views

Optimizing the reading of web.config

Here's the issue. When I build an asp.net application I create a singleton to read the values from the web.config file so that the values are only read once and gives a slight speed increase to the ...
15
votes
1answer
7k views

What is better for Lazy-Loading Navigation Properties of detached Self-Tracking Entities through a WCF service?

I have a WCF client which passes Self-Tracking Entities to a WPF application built with MVVM. The application itself has a dynamic interface. Users can select which objects they want visible in their ...
4
votes
2answers
5k views

Is this a reasonable Trie implementation?

http://en.wikipedia.org/wiki/Trie The basic idea is to support fast searches via prefix matching. In my implementation, I allow each node to store all of the words that match its given prefix, and ...
4
votes
1answer
232 views

Wrapper for dynamic behavior

I am writing a wrapper for dynamic behavior in C#. If I use GetMethod(), then an exception is thrown when there is more than one method (overloads). I figure it ...
14
votes
10answers
12k views

Looping through a collection

In the situation where I am looping through a collection looking for an item, is it better practice to break before I return or ...
7
votes
4answers
659 views

Managing part types and counts

Both functions look fairly similar to each other, but they are different in the type of string. I have 6 functions like this and all differ only in the "string cmd". Any ideas on how I can put it all ...
6
votes
3answers
1k views

Performance optimization for Linq To SQL

I have been working with C# for quite some time but relatively new to the concepts of lambdas and Linq. I was working with a Linq To SQL example and trying to write a generic solution for executing a ...
10
votes
3answers
1k views

FTP Download Helper Method

I'm currently using an Open Source FTP library in all my projects as I've never managed to code a decent FTP Helper Library based on the C# 4.0 API. What do you think about this approach? I'm not ...
7
votes
2answers
32k views

Is there a better way to search directories for a file or files?

Edit: The purpose of this method is to search a specific directory for a given file type, ex. (*.txt, *.pdb, *.exe") then move the file(s) to a given destination directory and delete the original ...
6
votes
1answer
4k views

Why is this code to paste into a DataGridView so slow?

...
32
votes
1answer
16k views

Extension methods to make ConcurrentDictionary GetOrAdd and AddOrUpdate thread safe when using valueFactory delegates

The ConcurrentDictionary<T,V> in .NET 4.0 is thread safe but not all methods are atomic. This points out that: ... not all methods are atomic, ...
3
votes
1answer
668 views

MVP presenter code in C# - possible troubles with DTO's

I am making a website using the MVP pattern. It is a simple website, so for the repository I use Linq2SQL. My architecture is basically: (View - Presenter) - Service Layer - Domain Models. The View ...
6
votes
1answer
1k views

View Model Base

I needed to write code in WPF for a client. The application is done with prism (not my decision, they already had people working on it), so I got a sparkling clean new module to work in. Since this ...
10
votes
6answers
7k views

Getting the miliseconds from now to the next midday

I need to get the total milliseconds to the next mid-day (12:00:00) to signal a timer that will run once a day. Assuming the application can be shut down and started anytime, is this code to get ...
5
votes
1answer
12k views

Storing Temporal Message Lists in ASP.NET MVC TempData

I've been using the following the code to store temporal error messages in TempData, to be displayed from my master page on production sites without any problems, ...
16
votes
8answers
3k views

Long function as a lambda, right or wrong? [closed]

I have been reviewing the code of a new co-worker and, although in general I think it's OK, there's a thing that causes me mixed feelings: ...
4
votes
4answers
3k views

Asynchronous website monitor

I have a class which is responsible for checking whether a website is up or down. I've made it to run asynchronously, but I would like critique if this is a good/bad way or if there is another better ...
4
votes
2answers
2k views

Small method for saving student attendance

...
5
votes
2answers
784 views

OpenGL VertexArrayObject class

It seems to play up sometimes and I'm not sure if this is due to the class itself or the way I'm using it. Can someone confirm that this is a 'good' implementation of a ...
2
votes
1answer
877 views

How would I unit test a method that gets data from an RSS feed?

I have a method that gets an RSS feed using LINQ to XML and returns a collection of an object that grabs only the data I need. There's really only one other method in the class I'm concerned about ...
5
votes
2answers
364 views

Is ToEnumerable<T> for multiple items a good practice?

In the similar vein as ToIEnumerable and FromSingleItem Is this a good improvement for making lists on the fly? ...
2
votes
1answer
548 views

Refactor for using ChannelFactory

I use VS 2008 and .NET 3.5 I have this code using CustomChannelFactory and Proxy ServiceReference. I would like refactor using lambdas, Action, ... any suggestions ? ...
4
votes
3answers
552 views

LISP-like list class

So, here's my code: ...
7
votes
2answers
1k views

XML settings implementation

I'm trying to figure out how to do this more dynamically. Right now I save each and every form field individually/manually. I would love to maybe have some kind of master form list that I could loop ...
6
votes
2answers
3k views

Simple clock view model

I have been trying to wrap my head around MVVM for the last week or more and still struggling a bit. I have watched Jason Dolingers MVVM video and gone through Reed Copsey lessons and still find ...
14
votes
5answers
1k views

What’s your opinion on a Throw() method?

Lately I seem to run into a situation very frequently where I want to write something like the following: ...
11
votes
3answers
7k views

Searching a sequence for a pattern

I have written the following tiny extension method to help me when I'm working with sequences in which I have to find a pattern. ...
11
votes
4answers
3k views

Composite and Visitor patterns for tree-based survey functionality in C#

I have written some survey functionality for a project. Basically, a generic survey form that can be composed of sections and questions. I have a Survey class, <...
9
votes
3answers
568 views

Are these endless if statements a bad pattern?

I'm only asking because almost the entire code base I've inherited here, in C# and PHP, looks like this: ...
5
votes
1answer
647 views

Implementation of String.prototype.replace

With just a brief look over I can think of a large amount of changes that would improve the clarity but I would love to see how someone else would refactor this mess. Spec Code ...
4
votes
2answers
871 views

Custom UIElement Animations

Having fancy animations in WPF is quite nice so I tried to implement a generic fading animation for UIElements which I use for the Popups in my application. I was ...
11
votes
1answer
21k views

Get params from a URL

I want to write my own version of HttpUtility.ParseQueryString, because it is not included in the .NET Framework Client Profile. My code is pretty straightforward ...
8
votes
3answers
917 views

Stack Overflow like pager

I've been working on a Stack Overflow like pager for my personal use and I've gotten everything working pretty good. Some of my logic is a bit suspect though, especially the logic in the Pager class ...
17
votes
11answers
1k views

Reversing a string

I had this as an interview question, and the interviewer pointed this out. Here's what I wrote: ...
5
votes
4answers
281 views

Adjusting integer based on multiple elements in int array

I'm working with the following code which adjusts an int based on multiple elements of an integer array. I am wondering if there's a cleaner, easier-to-read construct for this: ...
6
votes
4answers
658 views

Is there a shorter way to write the following if statements?

I have the following code which uses four if statements to check the value in four different combo boxes. ...
5
votes
2answers
3k views

Generic BinaryReader/Writer Read/Write methods

I have an extension that implements all the BinaryReader/BinaryWriter in the Stream class. I want to create generic methods for them. Is there a nicer way of doing this? ...
7
votes
2answers
816 views

Scripting language parser

I'm making a scripting language parser and it's shaping up well but it takes about 30ms to do 30 or so odd/even checks. Profiler tells me that it's taking most of ...