TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ronald Rex
NA
69
1k
Delegates and Lambda Expressions
Dec 27 2018 7:49 PM
12/27/2018 7:47:30 PM
Hello Friends,
I was wondering do I need to refactor this codes that is using a delegate with a lambda expression, or is this best practice? Thanks !
namespace
Delagate
{
delegate
bool
MeDelagate(
int
n);
class
Program
{
//static bool LessThanFive(int n) { return n < 5; }
// static bool LessThanTen(int n) { return n < 10; }
//static bool GreaterThanThirteen(int n) { return n > 13; }
static
void
Main(
string
[] args)
{
int
[] numbers =
new
[] { 2, 7, 3, 7, 9, 17,5, 1, 8, 1700 };
IEnumerable<
int
> result = RunNumbersThroughGauntlet(
numbers, n => n > 1500
);
foreach
(
int
n
in
result)
Console.WriteLine(n);
}
static
IEnumerable<
int
> RunNumbersThroughGauntlet(IEnumerable<
int
> numbers, MeDelagate gauntlet)
{
foreach
(
int
number
in
numbers)
if
(gauntlet(number))
yield
return
number;
}
}
}
Reply
Answers (
2
)
How to read json data
What environment to write c# on