C# is a multi-paradigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform.

learn more… | top users | synonyms

2
votes
1answer
26 views

Lazy String.Split

C#'s String.Split method comes from C# 2.0, and lazy operations weren't a feature back then. The task is to split a string according to a (single) separator. Doing ...
2
votes
0answers
12 views

Improving LINQ expression with inner method call and switch statement

I have the following class which returns an expression that then returns data. It seems a tad over complicated and I'm pretty sure LINQ has something to offer that makes my life much easier. But I ...
6
votes
2answers
121 views

Count duplicates

Problem statement: "Given an array of unknown size and containing only integers between 0 to 30 (inclusive), write an algorithm to find which numbers are duplicated, if any" My solution in C#: ...
1
vote
2answers
59 views

Predicate builder [on hold]

I have a predicate builder that initially evaluates to false. Because of this, the very next expression should be a logical Or. ...
4
votes
2answers
783 views

“Fancy-pants” vs “Cowboy” coding [on hold]

Based on the post I made here: RFC on "Factory" code and its responses, and my (inner) response to those responses, I'm beginning to wonder if it would be just as well to simply switch based ...
2
votes
1answer
43 views

Batcher using Microsoft.Tpl.Dataflow

What do you think? In particular, I'm not sure about my exception handling approach to raise errors when posting objects; but I couldn't come up with anything better. ...
0
votes
1answer
37 views

Timers to use various Task(s)

I am developing a C# program, which performs various tasks in parallel threads. I created a Base task and let all tasks derived from this class execute. I just want to know if this a viable approach ...
1
vote
1answer
37 views

LINQ grouping and sum

I have 4 properties which values I generate using LINQ: ...
-4
votes
3answers
75 views

Application search form

I have a search form in my application. When I search, it takes too much time to retrieve and display data, so I need to optimize this code. ...
1
vote
2answers
141 views
3
votes
2answers
222 views

Calculating checksum digits for barcodes

Every coder knows that if you give six developers an assignment to write a bit of code that will perform some specific task, you will end up with at least six different ways of doing it. I recently ...
4
votes
2answers
151 views

Database threading design

I am new to threading and I am a junior developer, so I guess there are many mistakes. My scenario is this: look into the database if there are data which should be sent add the data to the queue ...
5
votes
1answer
78 views

Truncating long strings when saving inventory items to database

To test incoming data for string values that are too large for the "database" (MS Access), I could do this: ...
5
votes
2answers
194 views

Splitting words in a selected file

I'm at loggerheads between performing operations one-by-one within a method, performing all of them at once (in one block) within the method, or breaking them up into four different methods. In terms ...
3
votes
1answer
32 views

RPG game using XNA

I know this code needs some organization like classes, enums, methods, arrays or something but I just want to know if I could have created a character movement script, thereby shortening the code ...
6
votes
3answers
228 views

Counting occurrences of different categories of characters

This is a sort of follow up to my previous question: Counting the number of character occurrences This time I have written code that still counts the number of different characters in a string, but ...
4
votes
1answer
776 views

Implementing cache for server

I've just implemented a cache for my server, and I'd like your thoughts about performance improvements and maybe some possible bug fixes: ...
2
votes
3answers
64 views

Simple wrapper for LocalReport

I've built a wrapper for a LocalReport and I would like to hear your suggestions about it: ...
2
votes
1answer
46 views

Same setup for many properties in Moq

I'm trying to use Moq to mock a rather large set of interfaces in an object. I'm trying to capture the behavior of retaining a dirty flag when properties are set and I'm hoping there is a cleaner way ...
-4
votes
0answers
15 views

Translate sql query to linq c# [on hold]

please help me to convert this query to linq c# ...
2
votes
3answers
321 views

Filtering a list based on a value

Based on dropdown value and search text I need to filter a list and return. Method 1 ...
0
votes
0answers
23 views

Build a collection of CLR object using linq Dictionary<string,List<string,string>> [on hold]

I'm building a WCF service to retrieve a list of "AttributeName,AttributeGroup,AttributeValue" For example, ...
0
votes
2answers
66 views

String de-duplication using a custom string pool

First let me address why I'm not using the built-in string interning. My code is used in a utility that needs to free all of its memory once it's closed. Strings that are interned are not likely to be ...
4
votes
0answers
25 views

Is there a better SQLite update / insert pattern than this?

I've got a function which updates an existing record or inserts a new one, but it looks very clunky to me. ...
0
votes
4answers
170 views

Returning an amount

In this code snippet, I want to be able to return the Amount as it is, unless the CashFlowTypeID is 12, 13, 14 or 15, in which ...
4
votes
2answers
367 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 ...
-1
votes
4answers
167 views

Finding the lowest terms for fractions in C#

I have been working on this Rational Operations calculator where you can input two rational numbers and can add, subtract, multiply and divide and the final output is the reduced answer. For example: ...
5
votes
2answers
77 views

Simple streaming parser to extract columns

In reply to previous question I rewrote ColumnReader and would like more suggestions ...
13
votes
7answers
4k views

Checking if two strings are an anagram

This is my sample code to check if a given pair of strings are anagram or not. ...
4
votes
3answers
525 views

Nit picking performance on this search code

I am working on a fairly complex (at least it feels complex to me at the moment) search program and am looking to possibly increase the performance. Everything works exactly how I want it to, but I'm ...
3
votes
3answers
4k views

Winform that exports a datagrid to Excel

I've just created a winform that exports a datagrid to Excel. Originally the file was never shown, but I was asked to give the option. So I put in a checkbox and modified the code. Is my if/else ...
-1
votes
0answers
45 views

Simplification of multiple for loops

I am iterating the same criteriaObject 2 items in a loop. Is there a way to make it in one loop for simplification? The 2nd loop is needed because I want this in ...
4
votes
3answers
65 views

Thread safe cache for write through and writeback

This cache is like a list where new elements are inserted in the middle, cache hits are put to head of the list and replaced elements are taken from the end. Would I just use a list the lookup would ...
1
vote
0answers
45 views

Repository pattern with data access objects

I started a new ASP.NET project in an effort to better learn SQL and Dapper ORM framework. My idea for data access: Have POCO entities, for each entity have DAO object. When I want to manipulate with ...
4
votes
2answers
56 views

Expression design

I'm designing a Tokenizer / Parser / AST. I'm wondering if this basic idea of an expression is good and if this way of implementing Simplification is good, or should I use something like the Visitor ...
5
votes
2answers
96 views

Using Linq syntax, how can I remove the select n+1 issue in this method?

I have the following code in a validation module. It works the way I want it to, but it has an obvious select n+1 problem. I would like to refactor this code to make a single call to the db to perform ...
8
votes
3answers
174 views

New event notification e-mailer

I created a New Event Emailer. this takes some fun events from a nice SQL query and creates a little HTML message and sends it to all the subscribers of events, when new event types are added we need ...
2
votes
2answers
67 views

Refactoring a loop through repetitive registers

I use NHibernate to search for data in the table Register. It contains monetary registers, incomes and outcomes. Some registers are repetitive, so I have managed to implement a few properties that my ...
31
votes
3answers
6k views

Exporting doc types using queues and multithreading

For a while I have been interested in seeing if some tasks work well when split across multiple threads. On the one project I have been busy with I have been creating a lot of small utility apps, to ...
3
votes
1answer
38 views

Redis Cache Data source code - Retrieve/Set/Invalidate actions

This is my RedisDataSource code. What I am mainly interested in is how the retry policy could be improved and if using WindowsAzure Trainsient Fault Handling this case (using Redis Azure Cache) makes ...
1
vote
1answer
22 views
2
votes
1answer
85 views

Moonshot & `Thread.Abort` - dealing with the fallout

Recently, I encountered an anomaly in the manner by which a worker thread was terminated. It prompted me to do some searching and I realized that I was constructing thread code in a haphazard manner. ...
1
vote
2answers
179 views

Dynamic Object Property in C#

I have the following code: ...
2
votes
2answers
70 views

Timestamp when file last modified in C#

I have the following code in PHP that appends a file path with a timestamp of when it was last modified: ...
3
votes
1answer
321 views

Computing average market spread in C#

My task is to compute average half spread in percentages on a stream of market. This is part of the coding assignment that I have received. ...
9
votes
2answers
147 views

Photo gallery user control

I am trying to create something that is very reusable here so that I can use it in other sites for other pages etc. This code is for a simple photo gallery, I took the code from here, but I ...
18
votes
10answers
687 views

Incrementing an integer when looping through a collection in C#

I have the following code that loops through a collection of objects and dumps different properties out to Excel. The whole j++ on every other line doesn't seem ...
-3
votes
0answers
22 views

compiler error - A get or set accessor expected @ Random randomNumbers = new Random(); [closed]

My question is how to get this compiler error in the Title line fixed? Yes this is a homework problem. Exercise description is at end of code. ...
0
votes
1answer
41 views

Remove particular element from an array and return indices of other elements

I'd like to get the indices of elements of an array with particular element. Is it okay or, or how can I make it even better? ...
12
votes
10answers
10k 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 ...