Questions tagged [c#-2.0]

For issues unique to development in C#, version 2.0

C# is a high level, general-purpose, garbage-collected and object-oriented programming language created by Microsoft.

Version 2.0 of the language corresponds to the 3rd edition of the ECMA-334 standard and targets version 2.0 of the .NET Framework. Visual Studio 2005 was the first version capable of compiling C# 2.0 code.

The following major features were introduced in C# 2.0:

A complete list is available here on MSDN: What's New in the C# 2.0 Language and Compiler. Jon Skeet also briefly describes the new features of C# 2.0 here.

The complete language specification is available for download from Microsoft (Word .DOC format).

See also: C# 2.0 on Wikipedia

1668 questions
195
votes
2 answers

Convert array of strings to List

I've seen examples of this done using .ToList() on array types, this seems to be available only in .Net 3.5+. I'm working with .NET Framework 2.0 on an ASP.NET project that can't be upgraded at this time, so I was wondering: is there another…
Nick Rolando
  • 25,879
  • 13
  • 79
  • 119
109
votes
16 answers

How can I evaluate C# code dynamically?

I can do an eval("something()"); to execute the code dynamically in JavaScript. Is there a way for me to do the same thing in C#? An example of what I am trying to do is: I have an integer variable (say i) and I have multiple properties by the…
Adhip Gupta
  • 7,063
  • 7
  • 34
  • 46
88
votes
8 answers

Get Max value from List

I have List List, my type contains Age and RandomID Now I want to find the maximum age from this list. What is the simplest and most efficient way?
Waheed
  • 10,086
  • 20
  • 53
  • 66
79
votes
6 answers

How to convert Dictionary to Dictionary in c#

I have below code in C# Dictionary dObject = new Dictionary(); I want to convert dObject to Dictionary. How can I do this?
Manoj Singh
  • 7,569
  • 34
  • 119
  • 198
75
votes
4 answers

ExecuteNonQuery requires the command to have a transaction error in my code

I get the following error on cmd.ExecuteNonQuery. "ExecuteNonQuery requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been…
Rania Umair
  • 1,965
  • 3
  • 18
  • 18
71
votes
3 answers

C# ASP.NET Send Email via TLS

In order to comply with HIPAA regulations, we need to send email from an external site (outside the firewall) to an internal Exchange server (inside the firewall). Our Exchange admins tell us we need to use TLS encryption to send mail from the web…
Allen
  • 1,165
  • 2
  • 11
  • 23
60
votes
3 answers

How to get list of one column values from DataTable?

I have DataTable. DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("id", Type.GetType("System.Int32"))); dt.Columns.Add(new DataColumn("name", Type.GetType("System.String"))); // more columns here I need list of "id" values. Can I do…
Kamil
  • 13,363
  • 24
  • 88
  • 183
58
votes
3 answers

Forwarding events in C#

I'm using a class that forwards events in C#. I was wondering if there's a way of doing it that requires less code overhead. Here's an example of what I have so far. class A { public event EventType EventA; } class B { A m_A = new A(); …
user3891
  • 9,101
  • 4
  • 24
  • 18
49
votes
4 answers

static readonly field initializer vs static constructor initialization

Below are two different ways to initialize static readonly fields. Is there a difference between the two approaches? If yes, when should one be preferred over the other? class A { private static readonly string connectionString = …
stackoverflowuser
  • 22,212
  • 29
  • 67
  • 92
48
votes
7 answers

How to use LogonUser properly to impersonate domain user from workgroup client

ASP.NET: Impersonate against a domain on VMWare This question is what I am asking, but the answer does not provide details on how the _token is derived. It seems to only use WindowsIdentity.GetCurrent().Token so there's no impersonation…
RichardTheKiwi
  • 105,798
  • 26
  • 196
  • 262
48
votes
7 answers

End of Stream encountered before parsing was completed?

I am trying to deserialize a stream but I always get this error "End of Stream encountered before parsing was completed"? Here is the code: //Some code here BinaryFormatter b = new BinaryFormatter(); return…
Mister Dev
  • 10,021
  • 12
  • 41
  • 33
42
votes
9 answers

Test events with nunit

I'm just starting with TDD and could solve most of the problems I've faced on my own. But now I'm lost: How can I check if events are fired? I was looking for something like Assert.Raise or Assert.Fire but there's nothing. Google was not very…
atamanroman
  • 11,607
  • 7
  • 57
  • 81
41
votes
7 answers

Why shouldn't I always use nullable types in C#

I've been searching for some good guidance on this since the concept was introduced in .net 2.0. Why would I ever want to use non-nullable data types in c#? (A better question is why wouldn't I choose nullable types by default, and only use…
Matthew Vines
  • 27,253
  • 7
  • 76
  • 97
40
votes
7 answers

C#: multiline text in DataGridView control

Is it possible for the DataGridView control to display multiline text in a cell? I am using Visual Studio 2005 and C#.
KeithDB
  • 415
  • 1
  • 4
  • 6
40
votes
7 answers

Speed up File.Exists for non existing network shares

I have to check if a set of file paths represent an existing file. It works fine except when the path contains a network share on a machine that's not on the current network. In this case it takes a pretty long time (30 or 60 seconds) to…
Vinko Vrsalovic
  • 330,807
  • 53
  • 334
  • 373
1
2 3
99 100