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

learn more… | top users | synonyms

-1
votes
0answers
17 views

Generic Task Blocking Queue with GUI [closed]

A generic blocking queue has the following properties: It is thread-safe. It allows queuing and de-queuing of items of a certain type (T). If a de-queue operation is performed and the ...
0
votes
1answer
27 views

Correct way to delete elements from a ConcurrentDictionary with a predicate

I have written a caching wrapper class for ConcurrentDictionary. Basically it has a timer that checks if items are expired and removes them. Since ConcurrentDictionary does not have RemoveAll method ...
0
votes
1answer
20 views

Making a property virtual to cause EF to load the property?

I am walking through a sample MVC4 ASP.Net tutorial available on PluralSight.com, by Scott Allen. I am in a section #5, Working with Data (part 2), "Listing Reviews". This application has a database ...
1
vote
1answer
18 views

Optimize Implementation - Wait for all threads using LINQ

In my program I read several information's about the system. I read each categories like CPU, memory, services, software and so on with a own thread. The main program have to wait for the longest ...
1
vote
3answers
46 views

Can this singleton be better

I need a global data in my application. My application uses several threads to access and add items to my global variable. The global variable is a ConcurrentDictionary I choose to ensure data is ...
0
votes
0answers
30 views

Design Pattern Question /ListBox.Items.Count

i built an Winform application with Pcapdot.Net DLL's that take Pcap file and play all the file packets into the machine network card. recently i have notice that all my main form (where all the ...
2
votes
1answer
74 views

Is there a safer/ more readable way of using this code?

Is there a safer/ more readable way of using this code? I gotta translate this code into a better , safer and more readable sample of code and get my onclick to work.(its currently called from another ...
5
votes
1answer
58 views

Recommended Naming for function that tests and mutates

I am a huge proponent of self-documenting code (when at all possible). I prefer to have code be self evident by the very nature of the names of the variables, methods, etc.. For instance: if ...
8
votes
6answers
636 views

Is the new version of this code more difficult to read and understand than the original? How can it be improved?

I was asked to do a code review for the following block of code. It implemented a bug fix to prevent some values being added to some drop down lists depending on the user's domain, in an ASP.NET ...
2
votes
1answer
41 views

Unit test provider roles

I am unit testing this role provider. I have a few asserts in the code for my test. I am sure there are more test I could preform. Does anyone have any suggestions for more test for this role of the ...
0
votes
1answer
10 views

Is this a sensible way to implement a model?

I've created the following model for an academic project, and I'm wondering if this is a sensible way to manage a model: using System; using System.Collections.Generic; using System.Linq; using ...
0
votes
1answer
51 views

can someone improve this code?

here is the code, HttpFileCollection collection = _context.Request.Files; for (int i = 0; i < collection.Count; i++) { HttpPostedFile postedFile = ...
0
votes
1answer
35 views

Is this code thread safe?

I do a code review for ASP.NET MVC RESTful service application code. Controller looks something like public class BarController : ApiController { [HttpPost] public void DoBar(byte[] rawData) ...
2
votes
1answer
38 views

A Better Way of Employing a Using Alias Directive

I understand .NET very well until Principals of OOP come into view, so I guess we can say very little. So to work on this, I am making a Console App that will Catalog my Digital Media to a MySQL ...
-1
votes
0answers
15 views

Razor Jquery Error [closed]

<script> @if (ViewBag.checkedArtikel != null) { foreach (int ac in ViewBag.checkedArtikel) { String temp = "'#addartikel" + ac + "'"; <text> ...
7
votes
3answers
143 views

Saving a contact and dealing with exceptions

try{save.Username = usernamedetails.Rows[0].ItemArray[0].ToString(); } catch{ save.Username = ""; } try { save.Firstname = dtdetails.Rows[0].ItemArray[1].ToString(); } catch { save.Firstname = ""; } ...
3
votes
1answer
74 views

Prime Numbers Store

Problem definition: Lets say we need to create a store for selling prime numbers. Users enter the store and ask to buy a number. If the number asked is a prime number, 1.1. then it's either ...
2
votes
1answer
29 views

Proper way to cancel WebClient in BackgroundWorker

I have a WPF application that needs to get a XML document using a web request. The request is based on an id that the user enters. If the user enters a second id, before the first returns, I would ...
-1
votes
0answers
31 views

Checklist for coding MVVM web application [closed]

We are a small team working on a web application using MVVM design pattern using technologies like .NET, Knockout and HTML. I am trying to come up with a code review process and as a first step trying ...
1
vote
1answer
24 views

XmlNodeList to ListItemCollection, a matter of elegance

at this moment I'm reading an XmlNodeList into a ListItemCollection one node at a time using a foreach. foreach (XmlNode node in authCompXml.SelectNodes("//Code")) { CompaniesList.Items.Add(new ...
1
vote
1answer
105 views

Implement recursion

The rules for this program are to: Generate n X n grid. Arbitrarily pick a point and grow a 'shape' based off that initial point. Must have at least 3 points. Strongly biased to not completely fill ...
2
votes
1answer
104 views

How to handle multiple queries in C#

In my project I am using 10-15 SQL queries, for that I have a common class for database connectivity and using that I have executed the queries by passing the connection, command and dataReader. ...
0
votes
2answers
84 views

Should I return true or false if both of the IP address strings are empty?

I am validating two IP addresses. I simply wrote a peice of code like if(string.IsNullOrEmpty(ip1) && string.IsNullOrEmpty(ip2) return true; But is this logically correct? What should ...
3
votes
1answer
33 views

Norms, rules or guidelines for calculating and showing ETA/ETC for a process

ETC = "Estimated Time of Completion" I'm counting the time it takes to run through a loop and showing the user some numbers that tells him/her how much time, approximately, the full process will ...
3
votes
3answers
136 views

Linq query performance improvements

As I am getting my Linq query to a functional point, I start looking at the query and think about all the "ANY" , and wonder if those should be a different method and then I have data conversions ...
1
vote
1answer
34 views

Based on Quine–McCluskey algorithm. Improve Nested loop for performance

I have a running program. That accepts 1 to 15 variables The goal of the program was a simplifier. Based on the Quine–McCluskey algorithm Consider 3 variables 000 001 010 011 100 101 110 111 I ...
5
votes
2answers
93 views

Improvement requested for: Generic Calculator and Generic Number

.NET does not support generic numbers. It is not possible to enforce a generic method with generic argument T that T is a number. The following code will simply not compile: public T ...
2
votes
1answer
37 views

Synchronization of remote files download

Preamble: it's a self-assigned and pure syntetic task to learn (and remember what I already knew) C# threads and synchronization and data structures. The original question was here ...
2
votes
1answer
25 views

Is there a method to add multiple properties to HtmlTextWriterStyle?

I am creating new elements for a webpage at run-time and I have code like this: var dynDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("Div") {ID = "dynDiv"}; ...
2
votes
3answers
134 views

Switch improvement

I have the following C# code, it actually works, but as you can see I have some bad coding (I think). For example... case "K1": switch (Convert.ToInt32(tb.Text)) { case 5: // ...
2
votes
5answers
206 views

Performance: Divide group of numbers into two groups of which the sums are equal

I have a piece of code that divides a group of numbers into two groups of numbers of which the sums are equal. I created this because of a StackOverflow question: ...
1
vote
0answers
54 views

Need guidance using Tasks

I am doing multithreading using TPL Tasks first time. This is what i have done so far and I want to do it the right way. I will really appreciate if you could honor me with your expert advice. I am ...
1
vote
0answers
41 views

Optimize HTML Document Function

bool sucess = false; var htmlDocument = new HtmlDocument(); while (!sucess) { try { var httpWebRequest = (HttpWebRequest) WebRequest.Create(aUrl); ...
1
vote
1answer
70 views

Using AutoMapper in ASP.Net MVC

I'd like to check my understanding and usage of the AutoMapper in my ASP.Net MVC app. I setup the maps in Application_Start: Mapper.CreateMap<Customer, CustomerViewModel>(); ...
0
votes
1answer
40 views

ASP.Net caching helper

I'm willing to simplify the use of the ASP.Net cache. I wrote this helper class : public static class CacheHelper { public static T GetCached<T>(string key, Func<T> initializer, ...
3
votes
3answers
150 views

Is this an acceptable method name?

GetCollectionWhereKeyStartsWith(string key) The intent of the method is to retrieve a sub-collecteion from a name value collection where the key starts with the passes key argument.
2
votes
1answer
53 views

Refactor code for API wrapper

I am looking for ways to improve my API wrapper for Pocket. So far, my code is quite compact and nice (I think), but I feel like there must be a better way to do this. This is the part where I think ...
-1
votes
1answer
79 views

ASP.NET MVC 4 Shopping Cart - Cannot update shopping car items using JQuery , Ajax, jSON, jGrid [closed]

I have this code in a C# MVC 4 VS2012 project. I need to be able to update the shopping cart with jSON data using JQuery/AJAX, i'm using jqGrid to display the data and pulling the shopping cart items ...
2
votes
1answer
65 views

Simple Freelock collection

I wrote simple lock-free collection class for saving items from multithreading code. I did it just for fun and experience. Can you check my code for potentially problems please? public class ...
0
votes
2answers
85 views

ThreadPool implementation in C#

The following code is a self-implementation of the static class ThreadPool in C#, only the QueueUserWorkItem (the simpler method), written to practice multithreading in the .NET environment and ...
1
vote
0answers
42 views

Best practices in implementing service methods

Consider the following architecture: ASP.NET MVC Application having controllers which depend on service classes (MembershipService, EmailService etc.) which in turn depend on data access context ...
1
vote
2answers
51 views

Setting Variable if it doen't exist in Dictionary

So I was wondering if this was good design from client side calls. In the event that the key doesn't exist, go ahead and add it. public static void SetVariable(string name, object value) { if ...
1
vote
0answers
85 views

How can I refactor this method so I don't use it in multiple places?

I have the following method which I use in multiple places, but it only differs by a few different things, so I was wondering how I can refactor it so I can have it in a common class and call it from ...
2
votes
3answers
105 views

Using Linq to select the first and last values

I want to get just the first and last values in a date range. I have the following code: using (var myEntities = new dataEntities()) { var myValues = (from values in myEntities.PointValues ...
1
vote
4answers
113 views

Improving performance hacker rank Median

im trying to compete on hackersrank and my awnswer got accepted but the times are not so good, i have a friend who sent the awnser in c# too but somehow made it a lot faster and im wondering what can ...
3
votes
3answers
69 views

pattern for validating an object against some condition

I have an object that's generated from an incoming json string. The string is deserialized in a custom converter that returns an object. This object has a method called IsValidForDB that checks if the ...
2
votes
2answers
51 views

Building Session-Variables from a sql stored procedure

I have been advised to submit my code here by a fellow Stack contributer as it was suggested the code could be further improved; Calling Code and attempt at building session variables: DataTable ...
2
votes
1answer
103 views

My implementation of lexicographic permutation in F# is 3x slower than C#?

Can someone help me with the following micro optimization for the f# code for lexicographic permutation? I have code in C#, which runs 0.8s in x86 and x64. As a learning practice, I translated it ...
2
votes
1answer
33 views

XML to Windows.Forms.Keys List

It took me a lot of poking around and unit testing to get the code to look like it is right now. So I have a XML file which in part looks like this <FunctionKeys> ...
4
votes
3answers
146 views

Using ref for value types - Is this the right usage or is it weird at multiple levels

I chanced upon this code written by the Solution Architect for a MS CRM project and I am lost for words. Am I going crazy or is this code OK? string returnedOptionSetStringValue=string.Empty; int ...

1 2 3 4 5 28