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

learn more… | top users | synonyms

0
votes
1answer
15 views

readability vs shorter code in returning from function

In something as simple as int sq(int x) { int y = x*x; return y; } versus int sq(int x) { return (x*x); } the former function requires an extra IL step. Is that IL extra step indicative of ...
4
votes
2answers
288 views

What are the valid uses of static classes?

I noticed that nearly every time I see programmers using static classes in object oriented languages such as C#, they are doing it wrong. The major problems are obviously the global state and the ...
1
vote
1answer
64 views

How to store/deal with data available to other classes

I'm writing a CAD program. Let's say I have in input class, this class reads various data from a text file and creates lots of lists/dictionaries and .... These data need to be accessed by other ...
0
votes
1answer
51 views

Tracing and Logging per item instead of per application

I'm building a service in .NET that process "things" in the background and I'd like to trace the execution of these things per item, not per application. Most logging frameworks (I'm familiar with ...
0
votes
2answers
187 views

Is using multiple static classes with maximum one public method is a good idea

I'm writing a structural detailing (CAD) software for concrete buildings in C#. I have defined like hundreds of static classes each with one public method and if needed some private methods. Each one ...
14
votes
9answers
2k views

Is it good practice to inherit from generic types?

Is it better to use List<string> in type annotations or StringList where StringList class StringList : List<String> { /* no further code!*/ } I ran into several of these in Irony.
0
votes
0answers
35 views

adding model specific CRUD operation web api endpoints

Are there are any major design flaws / smells in creating a web api as described below The models I have public class CourseModel { public String Name {get; set;} public ...
3
votes
2answers
242 views

C# static practices coming from dynamic background

I have been dappling in C# after coming from several years in PHP. I don't find the language particularly difficult, although there are considerably more constructs for me to get used to. My question ...
0
votes
0answers
26 views

Add Claims/Roles on Resource server (From Token Authorization server)

I've coded up a Web API 2 Authorization server that I am using to get a token for a given user. I can use that token to send requests to my Resource servers that use [Authorize] attribute in the ...
-1
votes
1answer
29 views

How to use MeshGrid method in Accord.Math Matrix Class? [on hold]

I am using the Accord.Math Namespace for Visual Studio in c#. I am trying to use the method MeshGrid<> under the Matrix class for the Accord.Math namespace. However, I am unsure how to implement ...
-2
votes
0answers
16 views

Change Windows Lock Screen background image in C# [migrated]

Is there a way to change the lock screen image like the wall paper in c# using pinvoke. [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern Int32 SystemParametersInfo(UInt32 ...
1
vote
1answer
54 views

OK to make a method generic just to pass in a System.Type?

Sometimes I have a function that takes a System.Type parameter, like: public void Foo(Type type) { // do something with "type" ... } This must be called like this: Foo(typeof(MyType)); I ...
-3
votes
0answers
47 views

automatically check textbox length c# [closed]

For a project at school, I use an RFID reader to read a code. The RFID reader is presented to my pc as an keyboard. What the program should do is scan a code, get some data from the database and move ...
-2
votes
0answers
35 views

Show BBCode in WPF [on hold]

I'm working on a C# WPF project where I want to store pages in bbcode (for example "[b]Bold[/b] [link]Other site[/link] etc.) and show it later. Now I'm hanging at this point: How do I show this with ...
1
vote
0answers
71 views

How does one enforce the implementation of a static method? [duplicate]

Of course the answer to the question above is, "you can't". But I didn't have a better way of describing what I'm looking for. If I did, I wouldn't be asking this question. My problem stems from a C# ...
5
votes
2answers
231 views

Should I use events or abstract methods?

Lets say I create an abstract class that manages some network functionality for me. I want to be able to be notified when something changes. For example: OnConnect or OnDisconnect. Should I create ...
7
votes
3answers
744 views

When to use .ToString() when concatenating a string in C#?

int a = 1; int b = 2; int sum = a + b; string expression = "Expression: " + a + " + " + b + " = " + sum; Console.WriteLine(expression); //displays Expression 1 + 2 = 3 Should I use: string ...
0
votes
2answers
91 views

Interface inherits from interface without specifying new member

Is it some kind of bad design to have something like this: public interface IFooStream { long Length { get; } long Position {get; set;} //... } public interface ...
2
votes
1answer
209 views

C# OOP Class Usage [duplicate]

I am just being picky and really wanted some of my code to look, feel, and be used a specific way but am not sure if its possible. I have a class I created that can be used like this ...
-1
votes
0answers
23 views

Best way to aproach creating an MRP [closed]

Ive been ask if I could create an MRP (Material requirements planning) program, from what I have read its seems like a complex program manager, I've been working on it for a couple of days now, and ...
-5
votes
0answers
71 views

how to scan a document using client side scanner in asp.net Web application [closed]

I'm using Asp.net web application (C# language). Want to Scan a document from clicking a button in web application (i.e. Browser). I already tried Twain tools But I need any other way to scan a image ...
1
vote
1answer
156 views

Is it OK for an interface to only communicate half of how something should work?

I have a service where certain other services can report their status to. By status I don't mean whether they are running or not, but whether they have received data. The point is that other services ...
0
votes
4answers
112 views

What is the preferred way to hold a file over multiple requests in MVC

I am building a wizard and the first step of this wizard is to let the user select a file. In the following steps I need this file to display some data from it and as a final step I have to import ...
17
votes
14answers
3k views

Is there ever a reason to use an array when lists are available? [closed]

It seems like List<T> in C# can do everything an array can do and more, and seems also just as efficient in memory and performance as an array. So why would I ever want to use an array? I'm ...
0
votes
2answers
90 views

Track a series of choices with a single number

I want to track a series of scored questions in a single number (the total score). Is that possible? and how? For example, I have 30 questions with either 3 or 2 choices. For any given question, the ...
3
votes
2answers
205 views

Using reflection vs creating a new class

I and a friend are having an argument on what is the better technique to use in the following scenario: An application we need to test has a number of components (lets call them Eggs); each component ...
3
votes
3answers
630 views

Why using string[] args in all main methods?

I'm a beginner in learning programming. I ask about using the string array in main method as a parameter. Why not writing the Main() method without the string array? What is the point of having this ...
-1
votes
4answers
90 views

Adding non distinct elements to a dictionary

Suggestions on a good pattern to follow to add elements to a dictionary where you want to add an element if it does not exist, else do nothing The 2 approaches I can think of are ...
1
vote
1answer
188 views

Efficiency of C# dictionaries

C# dictionaries are a simple way to find if something exists etc etc. I have a question though on how they work. Let's say instead of a dictionary I use an ArrayList. Instead of using ContainsKey (or ...
-3
votes
0answers
30 views

How to use a JOIN SQL statement in ASP.NET using Access? [migrated]

OK so I am a programming student with a headache that hopefully someone will be able to cure. I am currently creating a website using ASP.NET in Microsoft Visual Studio for a project and here is my ...
-1
votes
0answers
37 views

how to convert system.linq.IQueryable<int?> to int?[] [migrated]

foreach (var app in allList) { int?[] ids = Context.tblTransactionDetails .Where(x => x.IsActive == true) .Select(x => x.AdvertID); }
9
votes
5answers
2k views

Which are the cases when 'uint' and 'short' datatypes are a better fit than the standard int(32)?

I understand the differences in capacity and values they can represent but it seems as though people always use Int32 regardless of whether it is appropriate. No one ever seems to use the unsigned ...
3
votes
5answers
713 views

Creating a sort of 'in-language compiler'

I'm not saying I want to create a whole new compiler that's completely independent. I'm using C# Windows Forms and I want users to be able to write filtering syntax in a textbox withing my managed ...
0
votes
1answer
62 views

Is automatic conversion to collection types from non-collection variable a good idea? [closed]

Consider public void Do(string[] aBunchOfStrings) { } or public void Do(IReadOnlyList<string> aBunchOfStrings) { } Would it be a bad idea to allow the function call Do("woei"); resolve ...
0
votes
3answers
102 views

Various methods manipulating same member variable versus each takes inputs and provides output [closed]

As software design paradigm which is better? to let various methods manipulate a member variable, or define each method or function to take some inputs and provide some outputs? For example class ...
-4
votes
0answers
31 views

How to export multiple resumes (created by gridview in html format) [migrated]

First of all I want to convert the resume bound with grid to a .doc file. I HAVE used the following code. But the problem is that it export only 1 resume to Word doc. I have to allow the client to ...
3
votes
1answer
130 views

Usage of this keyword in constructor chaining?

I am reading msdn documentation for this keyword. They gave three usages for this keyword as follows To qualify members hidden by similar names To pass an object as a parameter to other methods To ...
3
votes
3answers
230 views

ASP.NET MVC should I reference the DAL from the UI?

I am developing an ASP.NET MVC application, and I have three projects: UI (with the system.web.mvc reference, BL and DAL references) BL (business facade and business objects) DAL (contains my ...
0
votes
1answer
109 views

Multi Page in WPF [closed]

I'm developing mutliple apps (C#/WPF) now and I'm always bothering about one thing: If you wanna use multiple pages (like step by step stuff) theres no clean way to do that. Mostly I'm using a frame ...
-1
votes
3answers
154 views

Cleaner C# without unneeded indents [closed]

In OO languages, at least C#, everything has to be in a class. Sometimes, everything is in a namespace as well. Just about literally all the code in one class is going to be automatically indented ...
0
votes
2answers
159 views

if a c# interface contain only getter and setter definition, is it a code smell?

A project that I am working on has the following code for interface example: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test { public ...
0
votes
0answers
47 views

Totalising and condensing data values from multiple arrays into a single array [migrated]

My fledgling programming skills have hit a wall. I could get this working, but the code stinks and I'm convinced there must be a more efficient way I just don't know it yet. I have a web service ...
0
votes
3answers
160 views

Using action array vs Switch Case [closed]

I have an occasion of code in which I will draw a different set of buttons in a screen (depending on the number of the buttons). One thought (and my current implementation) is to use an action array ...
38
votes
10answers
5k views

Should I accept empty collections in my methods that iterate over them?

I have a method where all logic is performed inside a foreach loop that iterates over the method's parameter: public IEnumerable<TransformedNode> TransformNodes(IEnumerable<Node> nodes) { ...
0
votes
2answers
175 views

Bad Practice using Auto Generated Classes for Data Access

I've seen this before but haven't found concrete reasons. When you add Entities to your EF model, EF auto generates classes for these entities. In terms of DataAccess, why is it preferred to not ...
0
votes
1answer
83 views

Async properties in interfaces to cater for the possibility of expensive first-time evaluation: Is this a good idea?

First of all, sorry if this post is too long. I'll start with the… Short version: Is it generally advisable or a good idea to design an interface property as asynchronous simply because we cannot be ...
1
vote
2answers
139 views

How to write a custom EventHandler class

When I started using Java, I created a custom Event class to mimic C#'s implementation of Events. Since then, I've added some other features, like event listener priorities, and cascading events were ...
-5
votes
0answers
106 views

Why should I ever implement structs? [duplicate]

Structs are value types so they're more expensive to handle. Classes are more capable that Structs. What are the reasons to ever choose to use a Struct in C#?
0
votes
1answer
213 views

Speech Recognition in the .NET framework is not efficient [closed]

I want to create a Virtual Keyboard that can catch whatever key you 'speak' and send the keystroke to the active application. The Virtual Keyboard part and linking it to Speech Recognition will be ...
11
votes
7answers
2k views

Name/Fix for Production Code Whose Sole Purpose is to Facilitate Testing? [duplicate]

The linked "duplicate" question is an iffy match at best, because it's asking is pattern X OK (YES/NO) and I'm clearly already in the NO camp, and subsequently asking what is pattern X called ...