Browsing Questions About c# (1)



When setting a form's opacity should I use a decimal or double?

I'm new to C#, and I want to use a track-bar to change a form's opacity. This is my code: decimal trans = trackBar1.Value / 5000; this.Opacity = trans; When I try to build it, I get this error: Cannot implicitly convert type 'decimal' to 'double' I tried making trans a double,…

Are there any conversion tools for porting Visual J# code to C#?

Are there any conversion tools for porting Visual J# code to C#?

How do I calculate someone's age in C#?

Given a DateTime representing their birthday, how do I calculate someone's age?

How do I calculate relative time?

Given a specific DateTime value, how do I display relative time, like 2 hours ago 3 days ago a month ago etc, etc...?

What's the difference between Math.Floor() and Math.Truncate() in .NET?

What is the difference between Math.Floor() and Math.Truncate() in C#?

How do I fill a DataSet or a DataTable from a LINQ query resultset?

How do you expose a LINQ query as an ASMX web service? Usually, from the business tier, I can return a typed DataSet or DataTable which can be serialized for transport over ASMX. How can I do the same for a LINQ query? Is there a way to populate a typed DataSet or DataTable via a LINQ query?: …

Reliable Timer in a Console Application

I am aware in .net there are three timer types (see http://msdn.microsoft.com/en-us/magazine/cc164015.aspx ). I have chosen a the threaded timer as the other types can drift if the main thread is busy and I need this to be reliable. The way this timer works in the control of the timer is put on…

How do I get a distinct, ordered list of names from a DataTable using LINQ?

Let's say I have a DataTable with a Name column. I want to have a collection of the unique names ordered alphabetically. The following query ignores the order by clause. var names = (from DataRow dr in dataTable.Rows orderby (string)dr["Name"] select (string)dr["Name"]).Distinct()…

Anatomy of a "Memory Leak"

In .NET perspective: What is a Memory Leak ? How to understand whether your application leaks? What are the effects? How to prevent a memory leak? If your application has memory leak, does it go away when the process exits or killed? Or do memory leaks in your application affects other …

Decoding T-SQL CAST in C#/VB.net

Recently our site has been deluged with the resurgence of the ASPRox bot SQL Injection attack. Without going into details, the attack attempts to execute SQL code by encoding the T-SQL commands in an ASCII encoded BINARY string. It looks something like this: DECLARE%20@S%20NVARCHAR(4000);SET%20…

Compressing / Decompressing Folders & Files in C#?

Anyone know of a good way to do this in C# quickly? Handling large files might be necessary. Thanks in advance? :)

How do I print an HTML document from a web service?

I want to print HTML from a C# web service. The Web Browser control is overkill, and does not function well in a service-environment, nor does it function well on a system with very tight security constraints. Is there any sort of free .NET library that will support the printing of a basic HTML pa…

Floating Point Number parsing: Is there a Catch All algorithm?

One of the fun parts of multi-cultural programming are numbers formats. Americans use 10,000.50, Germans use 10.000,50, French use 10 000,50 etc. My first approach would be to take the string, parse it backwards, until I encounter a separator and use this as my decimal separator. There is an ob…

Adding scripting functionality to .NET applications

I have a little game written in C#. It uses a database as back-end. It's a trading card game , and I wanted to implement the function of the cards as a script. What I mean is that I essentially have an interface, ICard , which a card class implements ( public class Card056 : ICard ) and which …

How do you sort a C# dictionary by value?

I often have a Dictionary of keys & values and need to sort it by value. For example, I have a hash of words and their frequencies, and want to order them by frequency. There's SortedList which is good for a single value (frequency), but I want to map it back to the word. SortedDictionar…

Next Page >