Click here to Skip to main content
15,898,222 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to get textbox control? Pin
Judah Gabriel Himango17-May-07 5:47
sponsorJudah Gabriel Himango17-May-07 5:47 
QuestionHelp needed to convert function to a generic function Pin
Jim Taylor17-May-07 3:11
Jim Taylor17-May-07 3:11 
AnswerRe: Help needed to convert function to a generic function Pin
Not Active17-May-07 4:12
mentorNot Active17-May-07 4:12 
GeneralRe: Help needed to convert function to a generic function Pin
Jim Taylor17-May-07 4:59
Jim Taylor17-May-07 4:59 
AnswerRe: Help needed to convert function to a generic function Pin
Judah Gabriel Himango17-May-07 5:11
sponsorJudah Gabriel Himango17-May-07 5:11 
GeneralRe: Help needed to convert function to a generic function Pin
Jim Taylor17-May-07 5:34
Jim Taylor17-May-07 5:34 
GeneralRe: Help needed to convert function to a generic function Pin
Not Active17-May-07 6:20
mentorNot Active17-May-07 6:20 
GeneralRe: Help needed to convert function to a generic function Pin
Judah Gabriel Himango17-May-07 7:15
sponsorJudah Gabriel Himango17-May-07 7:15 
The real trick of the above solution, of course, is the Converter<int, T> delegate; without it, we'd have to resort back to the a bunch of if/elses using hard coded types. That's no fun.

The yield stuff is really nice. LINQ uses it heavily; you can imagine the LINQ 'where' keyword actually uses a function underneath the hood:

public static IEnumerable<T> Where<T>(IEnumerable<T> items, Predicate<T> criteria)
{
   foreach(T item in items)
   {
      if(criteria(item)) yield return item;
   }
}


Of course, with current C# 2 syntax, consuming this is a little ugly:

int[] ints = {5, 10, 15, 20};
IEnumerable<int> evenIntegers = Linq.Where(ints, delegate(int i) { return i % 2 == 0; });


C# 3 makes this a little better with lambda expressions:

IEnumerable<int> evenIntegers = Linq.Where(ints, i => i % 2 == 0);


C# 3 improves it further by extension methods: taking static methods like our Where method and making them appear to be instance methods:

IEnumerable<int> evenIntegers = ints.Where(i => i % 2 == 0);


Better, but still a little odd. The "language integrated" part of LINQ adds some new keywords to C# 3:

IEnumerable<int> evenIntegers = from ints where i % 2 == 0 select i;


Pretty cool stuff; builds heavily on C# 2's delegate inference, anonymous methods, and yielding iterators.

And lastly, it's rather laborious to type IEnumerable<int> all over:

var evenIntegers = from ints where i % 2 == 0 select i;


Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Funny Love
The apostle Paul, modernly speaking: Epistles of Paul

Judah Himango


AnswerRe: Help needed to convert function to a generic function Pin
Nissim Salomon20-May-07 0:19
Nissim Salomon20-May-07 0:19 
QuestionWhat are the Books on C#..?? Pin
IamPoojaa17-May-07 2:39
IamPoojaa17-May-07 2:39 
AnswerRe: What are the Books on C#..?? Pin
Sathesh Sakthivel17-May-07 2:51
Sathesh Sakthivel17-May-07 2:51 
GeneralRe: What are the Books on C#..?? Pin
IamPoojaa17-May-07 3:08
IamPoojaa17-May-07 3:08 
GeneralRe: What are the Books on C#..?? Pin
Sathesh Sakthivel17-May-07 3:12
Sathesh Sakthivel17-May-07 3:12 
AnswerRe: What are the Books on C#..?? Pin
Kevin McFarlane17-May-07 3:13
Kevin McFarlane17-May-07 3:13 
QuestionTAPI Multmedia transmission Pin
CallieClearence17-May-07 2:21
CallieClearence17-May-07 2:21 
QuestionDiff b/w Windows Control Library and Class Library Pin
Rahul8317-May-07 0:52
Rahul8317-May-07 0:52 
AnswerRe: Diff b/w Windows Control Library and Class Library Pin
Pete O'Hanlon17-May-07 1:54
mvePete O'Hanlon17-May-07 1:54 
QuestionHow to connect c# (2.0 Framework [Dotnet 2005]) desktop application with ms sql 2000 Pin
prince_ppy17-May-07 0:42
prince_ppy17-May-07 0:42 
AnswerRe: How to connect c# (2.0 Framework [Dotnet 2005]) desktop application with ms sql 2000 Pin
andre_swnpl17-May-07 0:44
andre_swnpl17-May-07 0:44 
GeneralRe: How to connect c# (2.0 Framework [Dotnet 2005]) desktop application with ms sql 2000 Pin
prince_ppy17-May-07 0:48
prince_ppy17-May-07 0:48 
GeneralRe: How to connect c# (2.0 Framework [Dotnet 2005]) desktop application with ms sql 2000 Pin
andre_swnpl17-May-07 0:56
andre_swnpl17-May-07 0:56 
AnswerRe: How to connect c# (2.0 Framework [Dotnet 2005]) desktop application with ms sql 2000 Pin
Christian Graus17-May-07 1:10
protectorChristian Graus17-May-07 1:10 
AnswerRe: How to connect c# (2.0 Framework [Dotnet 2005]) desktop application with ms sql 2000 Pin
Nouman Bhatti17-May-07 1:48
Nouman Bhatti17-May-07 1:48 
Questionwriting with different color in excel Pin
Ankit Aneja17-May-07 0:26
Ankit Aneja17-May-07 0:26 
AnswerRe: writing with different color in excel Pin
gauthee17-May-07 1:00
gauthee17-May-07 1:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.