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
0answers
14 views

Can we use memorycache in webservice running on different machine and client on other machine?(c#)

I have webservice and used memorycache to cache the lookups. My service is running on different machine. My client program accessing the that service is on other machine. suppose my client calls ...
0
votes
0answers
8 views

Anything wrong with this mergesort?

Any reviews/ways to speed up/general improvements for my Merge Sort? Maybe something to simplify it or add more to it? using System; using System.Collections.Generic; using System.Linq; using ...
0
votes
0answers
25 views

Need assistance creating a method to use in my code [on hold]

So I've created this program for a project that I am working on. At this point I am mostly done with what I want to do. However, I do not know how to create a method for doing a calculation for the ...
0
votes
0answers
24 views

How to move to MVVM

I made a WPF application using Devexpress and Ado.net Connectivity mode with data base. I have worked in other languages and have now moved to C#. I am also new to WPF. I wrote this code to edit ...
-1
votes
1answer
25 views

How can I map dynamic index in the string using c# [on hold]

string originaltext = "A man meet a man"; charArray[0]='A'; charArray[1]=' '; charArray[2]='m'; charArray[3]='a'; charArray[4]='n'; charArray[5]=' '; charArray[6]='m'; charArray[7]='e'; ...
0
votes
2answers
30 views

Design class to handle calls for support functions

For the following problem statement, I design following classes. Can you please tell me if this is the correct implementation or if there can be a better one? Let's say there is call center with ...
0
votes
1answer
41 views

Drag Drop, get filename and last 23 characters

I want to get the filename and last 23 characters when I drag into a textbox. I have it working, but I would like to just have one line. Currently, I think I am doing a bit of a workaround. As I ...
1
vote
3answers
68 views

I need to know if there are any issues in this code?

/// <summary> /// This function gets the unique identifier of a member by the given /// login user name of that member on our web site. /// </summary> /// <param name="userName">The ...
2
votes
2answers
49 views

How can I improve my RedBlackTree?

So far I've implemented a way to add to my RedBlackTree (Will be used with A* pathfinding - Hence the F value). I'm not entirely sure how to improve it further. I want to add a remove function to ...
1
vote
2answers
42 views

Way of coding in C# [on hold]

Sometimes I have to write big code in a class, so what I do is something like this, Class ABC //it's a web service class { Public void Method-1() //used "-" for easy to read { ...
0
votes
2answers
37 views

Refatoring Implementation in.NET

I have implemented the following code: class A { abstract void f1(Object obj, Object data); } class A1:A { void f1(Object obj, Object data) { m1(obj,data); } void ...
3
votes
1answer
57 views

Is this TrackBar volume control okay?

Is this code okay, or can it be improved? It changes the application's volume through the Trackbar (1-100, 1% to 100%). public static class NativeMethods { //Winm WindowsSound ...
3
votes
1answer
55 views

State Machine for Character

I come today with a state machine I'm currently working on. Problem: Given any State that the Character is in, a button press or combination of button presses can modify that state in a different ...
0
votes
1answer
39 views

What Rules should be used? [on hold]

Not really a review, but i wonder, what Rules in Microsoft Visual Studio should be used to analyze the code for you? I know it´s not perfect by any means, but i really like how it performs fast hints ...
1
vote
2answers
42 views

How to remove duplicate matching?

There are my shapes (for example): public abstract class Shape { protected int _id; protected string _description; public abstract string ToXml(); } public sealed class Triangle : Shape { ...
2
votes
3answers
48 views

How to access and share MVC Model

I have the following model; namespace Site.Models.Country { public class Country { public string CountryCode { get; set; } public string CountryName { get; set; } ...
1
vote
1answer
24 views

Extract data from one column of SQL Server table

I have an SQL Server table from which I want to extract data from one column (DD) and return as multiple columns. The data is in NVARCHAR and looks like: ...
0
votes
0answers
13 views

Get rid of long/Complex if..else statements using Chain of Responsibility? [migrated]

I've an HttpHandler, which allows users to login to a system by passing in an encrypted code. Inside the ProcessRequest it performs quite a few steps. Retrieve the encrypted code from request ...
1
vote
0answers
52 views

Confusion with Factory pattern regarding Liskov's Substitution Principle, code maintainability and Unit Testing? [migrated]

I have a confusion regarding Factory Pattern there are basically two ways You can implement that. Approach 1: public interface IProductFactory { IProduct GetProductA(); IProduct ...
1
vote
1answer
60 views

Proper way to compare two Dictionaries [on hold]

I am implementing an IEqualityComparer for Dictionary objects and am looking for input on a couple of different approaches. I define equality in this case to be that both dictionaries contain the same ...
4
votes
2answers
78 views

Idiomatic loop and break condition

I am calling a C library via P/Invoke. That library needs to be called in sucession with an increasing unsigned int, and returns a pointer. That pointer is then mapped to a managed type, until it ...
3
votes
5answers
101 views

Writing out names of files on local C drive to a text document

This program writes out all the files in the current directory level to a text file, outputs an array of sub-directories at the current level, then repeats this process until there are no more ...
1
vote
1answer
78 views

Separating work into classes, is this correct? [on hold]

I am trying to separate some work (or rather pieces of code into Classes) to clean up my code. But, I'm having a hard time understanding how it will affect everything. I am trying to keep the ...
1
vote
1answer
57 views

Simple way to decrement number within a repeating range

I currently have a solution to increment numbers within a range: i % x + 1 Where x is the maximum number in the range and i is the previous number. It is nice and simple, and gives this array: ...
1
vote
1answer
53 views

Better way to use a Condition (CancellationToken)

Is there a better way to write this, as i am using the condition of the Cancellation Token to tell if it should use a byte[] from another thread or not. SharpDX.Windows.RenderLoop.Run(form, ...
0
votes
1answer
37 views

Using Observables to read from Tcp [on hold]

Following a suggestion/answer to my question on Stack Overflow, I'm trying to work out how I could implement a 'fail-safe' Tcp reader based around Rx. The current system uses nested whiles and ...
2
votes
1answer
51 views

Cookie wrapper in MVC4 c#

I'd like to create a cookie wrapper in my application to help support a DRY approach to coding common cookie methods, provide intellisense for cookie-type properties (keys), and protect against ...
4
votes
2answers
166 views

How can I improve upon my A* Pathfinding code?

How can I make it faster, more efficient, and simpler? Are there any obvious mistakes I've made, or things which will make my code "fancier"? It's my first time working with any form of pathfinding, ...
2
votes
1answer
43 views

Sending emails using SMTP client

The following code gets the recipient's email address, email subject line and email body from a table. It then creates the emails and sends them to a pickup directory. There is a db connection class ...
2
votes
2answers
71 views

designing application using polymorphism

I have created a polymorphic system, but I don't know whether this is the correct way of doing it. Am I abusing Polymorphism here? Here is the code: class WriteObj { public string Obj1 { get; ...
1
vote
1answer
60 views

Need help optimizing code so that resizing of 884+ columns in grid does not lag

private void rect_ManipulationStarting(object sender, ManipulationDeltaRoutedEventArgs e) { startingColumn = Grid.GetColumn(e.OriginalSource as Windows.UI.Xaml.Shapes.Rectangle); ...
2
votes
1answer
103 views

Any way to make this more Elegant?

Is there anyway to make this piece of code more elegant? Cause, it´s not a nice view, but i can´t really see a way to Improve the looks of it, or shorten it. But hopefully there is. private void ...
0
votes
1answer
63 views

Using Threads, Is this a good way?

So, i have 2 threads, one listen on TCP, other Render in a loop. So, to Start and End, i have this code: private void checkBox1_CheckedChanged(object sender, EventArgs e) { try ...
0
votes
2answers
53 views

Write a class with some properties and indexed

Is there a better way to write it? I need the best way to write it. It is this principle? Please show me a better way it breaks SRP? public class PlacementLocation { public int Row { get; set; ...
3
votes
2answers
97 views

Are private extension methods a bad thing to use?

In C# I have the following two extension methods. public static void WaitForMilliseconds(this IWebDriver driver, int milliseconds) { var timeout = new TimeSpan(0, 0, 0, 0, ...
2
votes
1answer
48 views

Is this a good way to syncronize my Threads?

After getting much improvement, it´s still one issue that concerns me. And that is the sync between my 2 threads. I use AutoResetEvent, but sadly, it has some delay with it, and would love to use ...
1
vote
0answers
26 views

Multiple Ajax Requests per MVC 4 View

I'm using the repository pattern with a context and ninject as the IOC. I have a service which handles getting and setting page properties in the database. public class MyContext : DbContext { ...
3
votes
2answers
76 views

Parallel LINQ Performance [closed]

This a sample code, when it runs it take only about 46% CPU time I'm using code based on this sample to process big TSV files (from 100GB to 500GB) I tried to use BlockingCollection but performance ...
2
votes
2answers
60 views

Improve this embeding of size in Stream

I am embedding my size in a Stream in the first 4 byte. When I think about it, it should be possible to do it better, but that depends. Here is how I currently do it: bsize = ms.Length; ...
2
votes
1answer
70 views

How to remove duplicated code? AOP and Generics are Ok

I have figures - TriangleItem and CircleItem: public abstract class BaseItem { protected int _id; protected string _description; } public sealed class TriangleItem : BaseItem { public int ...
0
votes
0answers
41 views

Open/Close Connection in a Loop [closed]

I want to enroll certain students into a certain class. I obviously have tables for 'Students', 'Classes', and the 'many to many' table 'ClassesStudents' which has the candidate key (ClassID and ...
0
votes
1answer
111 views

Can this be improved by working directly with the MemoryStream?

I have a piece of code that has a bit of a problem. Not that it doesn't work, though. The problem I am having is figuring out the optimal way of working with the MemoryStream, which I find quite ...
5
votes
4answers
893 views

Using method inside method or not. Which one is better?

I have a method like this: courseInfo(x,y, getCourseImage(ImageUrl)). But I can write this method like this String courseImage=getCourseImage(ImageUrl); courseInfo(x,y,courseImage); Which one is ...
0
votes
0answers
16 views

How I could update a DB table using a POCO class bound in a DataGridView [migrated]

I try to explain better using an example: I create the class Product with attibutes like that: private string _ProductCode = ""; [DisplayName("ProductCode")] public String ProductCode { get { ...
2
votes
4answers
177 views

What is the meaning of this null checking?

I want to check null of a task type array-list in this way: if(tasks==null) but can I write this like if(null==tasks). Are there any different of these checking? What are the meaning of these two type ...
0
votes
0answers
39 views

Ping and write the Status, think it can be improved (Runs on GUI Thread?)

I am running a Timer for updating some of my operations, such as Buffers. But I also want Ping to be added. It is added, but I think it can be improved. This is because I think it's running on the ...
0
votes
3answers
83 views

Putting array name in variable and shortening code

I'm a beginner in C# and am doing a simple programming exercise. I would like to put the Item.price and Item.Name into Listbox2. Is it possible to put the array name into a variable and iterate with ...
2
votes
0answers
33 views

optimize the pagination of repeater?

Hi I have some problem in my View.ascx.cs because I'm using reuse my code and modified it based on the situation for example I when I apply pagination I have efferent code in all place just I wan to ...
2
votes
2answers
90 views

Interface programming with Data Access Layer

I have several controls that are bound from database tables. Putting my OOP thinking cap on I figured since all of the controls will have a SqlCommand name and an associated SqlDataReader object I ...
1
vote
1answer
53 views

Modeling a decision tree-like form

A picture says more than a thousand words, so here's a mock-up. The actual choices are different, this is just a sample. A user first has to choose between Red, Blue and Green. Upon selecting an ...