C# is a multiparadigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform.
2
votes
2answers
21 views
Need an advice - refactoring
I'm making a comparing section, which I've just started typing, trying to get something working. It's working now, but as you can see its pretty messy. I feel this could be done in one or two less ...
0
votes
0answers
18 views
Can anyone optimize the code for parallel programming and efficiency?
The parallel programming can be used in finding row total or column total.
namespace OneWayAnovaTable
{
public partial class OneWayAnovaTable : Form
{
public OneWayAnovaTable()
{
...
2
votes
0answers
14 views
I have a mathematical expression evaluator. The code works fine. Code reviews and suggestion to improve coding style are welcome
using ExpressionEvaluatorLibrary;
namespace ExpressionEvaluator
{
class Program
{
static void Main(string[] args)
{
ConsoleKeyInfo cki = new ConsoleKeyInfo();
...
0
votes
1answer
29 views
Is it necessary to move OpenFileDialog code for opening the files and put it into a separate method?
I want to separate the code inside my Add button click event from the code in order to make my code looks more arranged.
this is my code before these changes (i am using BackgroundWorker in order to ...
2
votes
2answers
43 views
More Elegant Solution to Logging Class
I got this class in C# which works fine. But I was wondering if there was a more elegant solution to what I am trying to do. It looks rather clumsy and inefficient for a Logging functionality.
The ...
0
votes
0answers
11 views
Type conversion from FORTRAN to C#
I have in F2008
module mod_Blood
use mod_liquid
implicit none
type, public :: typ_BloodComponents
character(len=5) :: name
real(DP):: salt
real(DP):: RBC
end type typ_BloodComponents
...
2
votes
2answers
53 views
Extension methods for class Type
While working on one of my projects I actively used Reflection. While working with class Type I expected methods: TryGetMember, TryGetProperty, TryGetField, TryGetMethod. I've implemented them as ...
0
votes
1answer
44 views
Class design question
i have Winform application and i want to separate the button click event from the main form.
my application has Add button who add files into my Listbox and until now all my code was inside this ...
0
votes
0answers
22 views
Read BER-encoded data in C#?
I've asked this in StackOverflow and got a nice advice by Chris Latta on asking here because, well, someone called Lex Li closed my question: ...
1
vote
0answers
61 views
What is this structure called?
So I've been writing this data structure for a few days, and now I'm really curious about what it actually is, and to get some critique on my logic.
A branch, based on this usage, exists when a HEAD ...
-2
votes
0answers
22 views
Jquery File Upload (blueimp/jQuery-File-Upload) - ASP.NET MVC - How to Cancel Upload Async [closed]
created this in my github repository where I have the code of JqueryFileUploadblueimp implemented with ASP.NET MVC. Need some help about it, because I would like to know how can I cancel an UPLOAD ...
1
vote
0answers
59 views
Generic Task Blocking Queue
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 ...
1
vote
2answers
49 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 ...
1
vote
1answer
23 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
30 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
57 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
32 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
92 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
83 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 ...
9
votes
6answers
743 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
45 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
17 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
54 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
36 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
41 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
4answers
183 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
83 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
38 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
33 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
26 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
106 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
108 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
87 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
34 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
145 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
35 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
100 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
141 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
220 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
55 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
42 views
Optimize HTML Document Function
bool sucess = false;
var htmlDocument = new HtmlDocument();
while (!sucess)
{
try
{
var httpWebRequest = (HttpWebRequest) WebRequest.Create(aUrl);
...
1
vote
1answer
74 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
43 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
165 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
55 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
102 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 ...