Questions tagged [c#-3.0]

C# 3.0 ("C# Orcas") introduces several language extensions that build on C# 2.0 to support the creation and use of higher order, functional style class libraries. The extensions enable construction of compositional APIs that have equal expressive power of query languages in domains such as relational databases and XML. Use this tag if your question specifically pertains to C# 3.0 specific features. Otherwise, just use the C# Tag.

New C# 3.0 features

Resources

FAQs

3719 questions
942
votes
109 answers

Metadata file '.dll' could not be found

I am working on a WPF, C# 3.0 project, and I get this error: Error 1 Metadata file 'WORK=- \Tools\VersionManagementSystem\BusinessLogicLayer\bin\Debug \BusinessLogicLayer.dll' could not be found C:\-=WORK=-…
Oliver
  • 35,233
  • 12
  • 66
  • 78
833
votes
20 answers

Distinct() with lambda?

Right, so I have an enumerable and wish to get distinct values from it. Using System.Linq, there's, of course, an extension method called Distinct. In the simple case, it can be used with no parameters, like: var distinctValues =…
Tor Haugen
  • 19,509
  • 9
  • 45
  • 63
656
votes
19 answers

Getting all types that implement an interface

Using reflection, how can I get all types that implement an interface with C# 3.0/.NET 3.5 with the least code, and minimizing iterations? This is what I want to re-write: foreach (Type t in this.GetType().Assembly.GetTypes()) if (t is…
juan
  • 80,295
  • 52
  • 162
  • 195
457
votes
7 answers

How to get index using LINQ?

Given a datasource like that: var c = new Car[] { new Car{ Color="Blue", Price=28000}, new Car{ Color="Red", Price=54000}, new Car{ Color="Pink", Price=9999}, // .. }; How can I find the index of the first car satisfying a certain condition…
codymanix
  • 28,510
  • 21
  • 92
  • 151
383
votes
4 answers

Populate XDocument from String

I'm working on a little something and I am trying to figure out whether I can load an XDocument from a string. XDocument.Load() seems to take the string passed to it as a path to a physical XML file. I want to try and bypass the step of first having…
StevenMcD
  • 17,262
  • 11
  • 42
  • 54
320
votes
17 answers

C# Lambda expressions: Why should I use them?

I have quickly read over the Microsoft Lambda Expression documentation. This kind of example has helped me to understand better, though: delegate int del(int i); del myDelegate = x => x * x; int j = myDelegate(5); //j = 25 Still, I don't…
Patrick Desjardins
  • 136,852
  • 88
  • 292
  • 341
282
votes
42 answers

What's the hardest or most misunderstood aspect of LINQ?

Background: Over the next month, I'll be giving three talks about or at least including LINQ in the context of C#. I'd like to know which topics are worth giving a fair amount of attention to, based on what people may find hard to understand, or…
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
206
votes
5 answers

In C#, What is a monad?

There is a lot of talk about monads these days. I have read a few articles / blog posts, but I can't go far enough with their examples to fully grasp the concept. The reason is that monads are a functional language concept, and thus the examples are…
Charlie Flowers
  • 17,338
  • 10
  • 71
  • 88
189
votes
5 answers

How do I use LINQ to obtain a unique list of properties from a list of objects?

I'm trying to use LINQ to return a list of ids given a list of objects where the id is a property. I'd like to be able to do this without looping through each object and pulling out the unique ids that I find. I have a list of objects of type…
mezoid
  • 28,090
  • 37
  • 107
  • 148
158
votes
7 answers

Implement C# Generic Timeout

I am looking for good ideas for implementing a generic way to have a single line (or anonymous delegate) of code execute with a timeout. TemperamentalClass tc = new TemperamentalClass(); tc.DoSomething(); // normally runs in 30 sec. Want to error…
chilltemp
  • 8,854
  • 8
  • 41
  • 46
143
votes
10 answers

Difference between Property and Field in C# 3.0+

I realize that it seems to be a duplicate of What is the difference between a Field and a Property in C#? but my question has a slight difference (from my point of view): Once I know that I will not use my class with "techniques that only works on…
p4bl0
  • 5,354
  • 5
  • 24
  • 25
141
votes
9 answers

AddRange to a Collection

A coworker asked me today how to add a range to a collection. He has a class that inherits from Collection. There's a get-only property of that type that already contains some items. He wants to add the items in another collection to the property…
TrueWill
  • 25,132
  • 10
  • 101
  • 150
131
votes
9 answers

Why must a lambda expression be cast when supplied as a plain Delegate parameter

Take the method System.Windows.Forms.Control.Invoke(Delegate method) Why does this give a compile time error: string str = "woop"; Invoke(() => this.Text = str); // Error: Cannot convert lambda expression to type 'System.Delegate' // because it is…
xyz
  • 27,223
  • 29
  • 105
  • 125
122
votes
7 answers

how to check if string value is in the Enum list?

In my query string, I have an age variable ?age=New_Born. Is there a way I can check if this string value New_Born is in my Enum list [Flags] public enum Age { New_Born = 1, Toddler = 2, Preschool = 4, Kindergarten = 8 } I could…
qinking126
  • 11,385
  • 25
  • 74
  • 124
107
votes
4 answers

Favorite way to create an new IEnumerable sequence from a single value?

I usually create a sequence from a single value using array syntax, like this: IEnumerable sequence = new string[] { "abc" }; Or using a new List. I'd like to hear if anyone has a more expressive way to do the same thing.
Marcel Lamothe
  • 12,452
  • 9
  • 34
  • 44
1
2 3
99 100