c#-2.0


How can i write anonymous method in my scenario


Let me tell you all that i am not getting any type of error in my code it is working perfectly fine, I am here to know one specific thing about Anonymous method. So firstly it is my code. I have a class called Employee. in which there are three auto implemented properties and a function which is returning the employees names who git bonus salary, I am using delegates so there is no logic in this function and that is the reason this class and method is reusable.
class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public int Salary { get; set; }
public static void BonusForEmp(List<Employee> emp, Bonus Isavailable)
{
foreach (Employee e in emp)
{
if (Isavailable(e))
{
Console.WriteLine(e.Name + " got bonus");
}
}
}
}
delegate bool Bonus(Employee Employes); // Delegate
Here It Is my Main method in which i create a list of employees and doing all the steps like creating a instance and passing the method as an argument.
List<Employee> EmpList = new List<Employee>();
EmpList.Add(new Employee() { Id = 1, Name = "A", Salary = 12000});
EmpList.Add(new Employee() { Id = 2, Name = "B", Salary = 7999 });
EmpList.Add(new Employee() { Id = 3, Name = "C", Salary = 1999 });
EmpList.Add(new Employee() { Id = 4, Name = "D, Salary = 20000});
Bonus B = new Bonus(BonusAvailabeFor); //instance of dlegate and pasing method name as an argument
Employee.BonusForEmp(EmpList, B); //using
Console.ReadLine();
So All of you thinking that where is my method(BonusAvailableFor) in which i did all the logical work which matches the signature of delegate? Here it is
public static bool BonusAvailabeFor(Employee eml) // the function with same signature of the delegate here we use our logic.
{
if (eml.Salary > 8000)
{
return true;
}
else
{
return false;
}
}
So this code is working so perfectly nice and returning the names of employee whose Salary > 8000.
I just read anonymous method somewhere that is inline expression that can be used wherever a delegate type is expected.They provide us a way to create instance of delegate without having to write a separate method .. the definition looks great it will reduce my lines of code if i can implement this in my scenario, so how can i achieved it ? <=== (My Question)

Related Links

Tag appears more than once while using Quickfix market data incemental refresh
c# exe throwing error only when run through task scheduler
HttpWebRequest WebException 401 in .net 2.0
Current Regional Settings to C# 2.0
I want to do an enqueue and dequeue for an array, but it shows that object reference not set to an instance of an object
Seat booking system information for C# Application
How to dispose OdbcConnection while trying to connect
Streamreader takes long time at consecutive times in C#
Dynamic tool tips for Tab control
Interface implementation issue when call function of perticular interface
How can I list what LSPs are installed, using C#?
How to validate it allows only numerics in c# textbox_TextChanged event
Multiple Bills Printing in C#
Shell Extension in C# with .Net 2.0/3.0/3.5
Inserting popup menu to explorer context menu in c#
EPPlus The type or namespace name 'OfficeOpenXml' could not be found (are you missing a using directive or an assembly reference?)

Categories

HOME
twitter
openmp
openstack
image-processing
fft
bpmn
alfresco
google-docs
gis
win32gui
fsm
umd
ezpublish
python-unittest
vault
etl
apache-cayenne
hex-editors
decomposition
highlight.js
footer
ab-testing
amazonsellercentral
errorlevel
arabic
excel-2007
claims-based-identity
wijmo
trading
dxf
one-to-many
dynamic-featured-image
user-interaction
compatibility
jspm
instant-messaging
http-status-code-503
airconsole
ioio
calibre
nssegmentedcontrol
overlap
main
mixture-model
android-browser
gzipstream
node-sass
wso2carbon
flickr-api
theming
hendrix
pnotify
blogengine.net
tizen-native-app
tropo
lowpass-filter
nstextview
colorama
slickedit
google-perftools
np-complete
knpmenubundle
akka-cluster
crosswalk-runtime
bonobo
nsfilemanager
markojs
react-native-listview
hexdump
xna-4.0
msys
lemon
android-listview
web-controls
sonarqube5.1.2
block-device
rake-task
pick
knuth
java.util.concurrent
android-imagebutton
socketexception
java-metro-framework
jubula
jquery-layout
rebol3
valuechangelistener
braille
srs
c18
sitemesh
dotnetnuke-5
android-screen-support
mhtml
code-cleanup
gnu-prolog
doh
zpt
gcj
netbeans-7.1
floating
datareader
lang
cxxtest
memory-size
iweb
aquaticprime
grid-system
ugc
.net-1.0
windows-live-messenger

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App