Tagged Questions

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

2
votes
2answers
27 views

Finding unconnected sets

I have a list of boxes, and wish to group them into unconnected sets of overlapping boxes. (Note that two boxes A and B may not overlap each other, but if they are both overlapped by a box C, they ...
1
vote
1answer
57 views

Functional Exception handling with TryCatchFinally Statement helpers

Hello All, I wrote something to the effect of a try catch finally statement helper in functional style so that I can shorten much of the code I'm writing for my Service Layer that connects to a sql ...
0
votes
0answers
20 views

How to draw a hollow triangle, provided the height of triangle to be given by user in c#? [duplicate]

I would like to share my code, which was an assignment by my senior to write a code which draws a hollow triangle of height, which would be provided by the user. The code can be viewed by the ...
2
votes
1answer
41 views

How to draw a hollow rectangle of rows and column provided by the console application?

Today, I am going to ask a question, for which I am going to answer by myself, the question was put forward by my senior to draw a hollow rectangle in C#, and with the condition that the rows and ...
-1
votes
0answers
20 views

Accessing controls of one form from the other form [closed]

Can anyone help me with this. I'm creating a program that asks the user to select what to order. When the user selects his choice in a form of a button, another form will then show with all the ...
2
votes
0answers
17 views

Variable cacheing [migrated]

Why in this part of code complete is chached static void Main() { bool complete = false; var t = new Thread (() => { bool toggle = false; while (!complete) toggle = !toggle; }); ...
1
vote
1answer
34 views

SQLite Helper Class

Hello guys recently i have implemented my SQLite helper class that supports sqlite in memory class to be opened to not to be lost. Here is the code : using System; using System.Collections.Generic; ...
2
votes
1answer
40 views

Improving the way a C# application communicates with a SQL database (Via SqlConnection)

*Originally posted this on stackoverflow but was told that it would be better suited here. So I'm looking for a better way to setup how an application talks with a database. I'm sure this question ...
1
vote
1answer
43 views

Producer/Consumer with some limitations

The code realizes producer/consumer problem with multiple producers and consumers. Have this code any potential deadlock or races? //RandomDataProvider.cs namespace MyNamespace.Core { using ...
2
votes
1answer
37 views

Are Request/Response Parameter Wrappers Good Practice?

I've seen several different ways to design WCF services, and it seems some developers prefer parameter wrappers while others favor 'naked' parameters. To explain what I mean, consider the following ...
2
votes
0answers
28 views

Expecting working sample of DeviceIoControl reviewed

I put the full code at the rear of this post. I've recently answered a question, and the detail explanation is posted in Physical disk size not correct (IoCtlDiskGetDriveGeometry) And en ...
0
votes
0answers
14 views

Use of “is” and “as” in multiple conditions [migrated]

Quite recently, I thought about the use of "as", "is" and direct cast in C#. Quite logically, it is a better idea to use : var castedValue = value as type; if (null != castedValue) { // Use ...
-1
votes
0answers
26 views

reading data from ms access database and display it a listbox [closed]

How do I read data in ms access database and display it in a listbox. I have the codes here but i got errors. private void button3_Click(object sender, EventArgs e) { using (OleDbConnection conn ...
0
votes
2answers
86 views

Wondering why they created a class instead of adding it to the current class

So for an example, the example site has two class public class LinqValueCalculator { public decimal ValueProducts(IEnumerable<Product> products) { return products.Sum(p => ...
2
votes
4answers
102 views

Designing a better logger class

Could you please critisize the logger class below? Can it be used in a multi threaded web environment? If not how can I improve it? Is there anything wrong with locking in WriteToLog method or ...
1
vote
1answer
83 views

Improving a Calculator Application

I have here a calculator created using C# that is running on a console. The calculator accepts a string input (e.g. 5+5) then produces the result (5+5=10). It will then prompt the user to enter ...
2
votes
1answer
34 views

Testing database table creation with NUnit

I'm new to using NUnit and have written a test to check for the existence of a database table. I have the below code that should check whether a new table named NewTable has been created in the ...
1
vote
0answers
7 views

Is there a proper way to create a file format? [migrated]

I'm building a proprietary file format for an application I wrote in C# .NET to store save information and perhaps down the line project assets. Is there a standard on how to do this in any way? I was ...
5
votes
0answers
80 views

Doubts about the quality of an API designed for use with minimal effort

This is going to be long, and I do hope it is going to make some kind of sense; I apologize if it doesn't. I'll try to provide exactly the amount of context that is necessary to understand the ...
5
votes
0answers
86 views

Best way to unit test methods that call other methods inside same class [migrated]

I was recently discussing with some friends which of the following 2 methods is best to stub return results or calls to methods inside same class from methods inside same class. This is a very ...
3
votes
1answer
84 views

Is this code as weird as I think it is?

Combing through legacy code, I found this: public static void SetupSiteDeptBox(string siteNo, System.Windows.Forms.ComboBox cbo, ref Hashtable DeptHash) { DeptHash.Clear(); if (siteNo != "") ...
1
vote
1answer
73 views

Is there a valid answer to this “Why?” comment?

This is probably too little to go on for a definitive answer, but in looking over some legacy code, I found this (a previous peruser commented "Why?") in what serves as the main form in a Windows CE / ...
1
vote
1answer
43 views

Is this enum declaration “wrong,” or is it just me?

Legacy code has this enum declaration: public enum ChangeListTypes { Always = 1, Never = 2, CostChange = 3, None = 0 } I would have done it this way: public enum ChangeListTypes { ...
2
votes
2answers
93 views

Determine if an int is within range

Can I somehow make this a bit cleaner using Math.[Somthing], without making a method for it !? int MaxSpeed = 50; if (Speed.X > MaxSpeed) Speed.X = MaxSpeed; if (Speed.X < MaxSpeed * -1) ...
0
votes
3answers
71 views

New to LINQ, not sure this is best practice

So i have a super class that has a 3 child classes. Those 3 child classes have multiple classes of their own. I was having troubles saving this into XML, so I decided to parse it out and do a little ...
2
votes
1answer
103 views

Too slow two strings comparer

I have 2 strings for example: abcabc and bcabca or aaaabb and abaaba I checked that second string is the same or not like first string but shifted. bcabca = ..abca + bc... Here is code it works ...
0
votes
4answers
77 views

Understanding Interface

//program.cs class Program { static void Main(string[] args) { Dog oDog = new Dog(); Console.WriteLine(oDog.Cry()); Cat oCat = new Cat(); ...
4
votes
1answer
65 views

C# 5 Async Await .Task.Factory.StartNew cancellation

I have the async code that implements cancellation token. It's working but Im not pretty sure if this is the right way to do it so I just want feedback about it. Here is the actual code: /// ...
3
votes
3answers
138 views

Optimization Of Code With Runtime of 150Hours

XPost from Stackoverflow questions as Nicholas Pickering kindly referred me to this. I've been working on a project where I am importing a large document of documents and tokenizing each document. I ...
3
votes
0answers
36 views

Distance checking of normalized vectors?

I've been learning C#/XNA in an attempt to make a game for the past few weeks so maybe this is an obvious newbie thing, but here goes: I've been making a fairly simple 2D game, so I have a list of ...
3
votes
2answers
70 views

What is the “correct” way to replace from a list chars in a string?

Often I need to clean a file name using Path.GetInvalidFileNameChars(), however I do not know of a way to search for any of the invalid letters (except by using Regex) in one pass. public string ...
2
votes
1answer
23 views

Multiple target method invocation wrapper

I'm currently working on a system using WCF to communicate between a Windows Service and one or multiple clients. Service is required to answer clients calls, as well as notify them of certain events, ...
0
votes
0answers
26 views

Data Access Objects and Entity Relationships

What is the proper way to structure DTO's for my tables? Three of my tables are Documents which contains Pages and Fontstyles. I am creating an EditDocument view in which I will edit these (and more) ...
3
votes
1answer
59 views

Async SQL C# class

I'm new here, bear with me if I did anything wrong asking this question :) I've written a class to make async sql calls and it appears to work like a charm! But I'm a bit concerned about what it ...
1
vote
2answers
68 views

Is wrapping the service layer worthwhile?

I have been trying to design a good data layer that will eventually be generated. I am wondering if I have missed anything. The basic architecture contains a service class that handles connecting and ...
0
votes
1answer
61 views

How can I implement the generic repository pattern and improve the performance for the code below?

I've used EF-DB first approach and have written a simple app to retrieve the data from the database and show it in the view. The code is simple and ok for a beginner like me, but how can I implement ...
31
votes
14answers
1k views

Cleaner way to code BOOL×BOOL→ENUM mapping?

Does this part look clean enough? Any suggestions on how to make it cleaner? if (isCheck) { if (isStuck) { return GameState.Mate; } else { return GameState.Check; ...
1
vote
0answers
52 views

Memory leaks and clunky TPL code [closed]

The problem my code tries to solve is the following: I need to update a specific part of the GUI. However, since database access is needed in order to perform that update, it must be done in a ...
0
votes
0answers
20 views

free memory in c# [migrated]

I would like to know if this following code is correct or source of bugs. In a unmanaged.cpp file: char *output[256]; extern "C" void firstfunction(unsigned short id, char **outputtemp, unsigned ...
6
votes
1answer
80 views

passing a selectlist to the view based on database models from viewmodel is a MVC anti-pattern?

We need to select a model reference from a view. To do this we need to add a dropdownlistfor. this is based on a selectlist containing database models. passing selectlists by viewbag this solves our ...
0
votes
1answer
88 views

Is this the proper way to find the subclass of a polymorphic superclass?

I came across polymorphism in the book that I'm reading and decided to do a little experiment. Essentially what I did was to create a base class called Asset and two subclasses that derive from Asset, ...
2
votes
3answers
85 views

Properties and on change events

So I made a socket communication library. And a part of it is IConnection public enum ConnectionState { NotConnected, Connecting, Connected, Authenticated, Disconnecting, Disconnected } public ...
2
votes
0answers
28 views

OPOS DirectIO event review

This may be a poor title name. So I'm basing what I did from this website http://forums.codeguru.com/showthread.php?231156-MFC-String-How-to-convert-between-a-CString-and-a-BSTR the idea is though ...
3
votes
0answers
72 views

Looping through columns in Entity Framework

Is there a cleaner/more efficient way to loop through the columns in EF implicitly than the way written below? static void Main(string[] args) { using (var db = new someDbContext()) { ...
-2
votes
0answers
32 views

Recursive Function for create Menu Tree from Database in Asp.NET & C# website [closed]

In My Asp.NET website I want to Create tree structured Menu from Database .
2
votes
1answer
101 views

Simple ThreadSafe Log Class

For the m_listeners BlockingCollection<>, I know it's a bit hacky right now, but I'm not sure what to use instead (List<>, Dictionary<>, something else?). I want to be able to add/remove ...
1
vote
1answer
50 views

WPF circle and line drawer solution

I've created a WPF program which can draw lines and circles on a canvas. It works well, but I don't think it's the best solution. How can I make it work better? How would you create this program? ...
4
votes
1answer
59 views

ObservablePriorityQueue<T> Implementation

I have a requirement in my current project that will need a Prioritised Queue that supports the IObservable interface. Please share any problems with the current implementation below: ...
4
votes
2answers
91 views

Task.Finally extension, good, bad, or ugly?

I wrote this, and it has helped to avoid the 'Some exception weren't handled' problem. Is there something glaringly wrong with this that I might have missed? /// <summary> /// Handles ...
4
votes
3answers
271 views

Is this interface too “god-like?”

I have an MVC framework I've written. I'm trying to abstract out ASP.Net specific bits as well as make it more testable. Previously, I relied on HttpContext.Current in many places, which proves to be ...

1 2 3 4 5 24