Difference between >= and =>

  • Thread starter Thread starter Rich P
  • Start date Start date
R

Rich P

I do sporadic C# coding where I mainly write VB.Net. I am now writing
more C# and am seeing constructs that I am not familiar with - like =>.

<= less than or eqaul to, >= greater than or equal to

but what is => ?

Rich
 
I do sporadic C# coding where I mainly write VB.Net. I am now writing
more C# and am seeing constructs that I am not familiar with - like =>.

<= less than or eqaul to, >= greater than or equal to

but what is => ?

=> is the same as >= and has been supported by BASIC for this side of
forever, so I'm surprised that you've never seen it. Actually, I didn't know
for a fact that it worked in C#, but I'll take your word for it. I know
there is definitely something out there that doesn't support it. T-SQL
perhaps?
 
Rich said:
I do sporadic C# coding where I mainly write VB.Net. I am now writing
more C# and am seeing constructs that I am not familiar with - like
=>.

<= less than or eqaul to, >= greater than or equal to

but what is => ?

It is the lambda operator (new in C# 3.0), and is used like e.g.:

delegate int del(int i);
del myDelegate = x => x * x;
int j = myDelegate(5); //j = 25

It is read as "goes to".

http://msdn.microsoft.com/en-us/library/bb311046.aspx



--
Rudy Velthuis http://rvelthuis.de

"From the moment I picked your book up until I laid it down I
was convulsed with laughter. Some day I intend reading it."
-- Groucho Marx (1895-1977)
 
Rich P said:
I do sporadic C# coding where I mainly write VB.Net. I am now writing
more C# and am seeing constructs that I am not familiar with - like =>.

<= less than or eqaul to, >= greater than or equal to

but what is => ?

Rich


If it is code similar to this, it is a predicate. This serves as an inline
function. In this case, the Where () functions calls this predicate to test
each color string to see if it starts with "R".

List<string> colors = new List<string>();
colors.Add("Red"); colors.Add("Green"); colors.Add("Blue");

var rs = colors.Where(x => x.StartsWith("R"));
foreach (string s in rs) Console.Out.WriteLine(s);
Console.In.ReadLine();
 
Thanks all for your replies. I did try google, but could not get
anything for =>. I should have tried lamda. I Have been reading up a
little bit about Lamda (anymous functions?) and I guess I will have to
start getting used to LinQ. Too much fun for a Friday afternoon.

Thanks again.

Rich
 
Family Tree Mike said:
If it is code similar to this, it is a predicate. This serves as an inline
function. In this case, the Where () functions calls this predicate to test
each color string to see if it starts with "R".

List<string> colors = new List<string>();
colors.Add("Red"); colors.Add("Green"); colors.Add("Blue");

var rs = colors.Where(x => x.StartsWith("R"));
foreach (string s in rs) Console.Out.WriteLine(s);
Console.In.ReadLine();

Sorry, the other guys are right. It's a lambda function.

Mike
 
Not in C#.

Ah, Lambda. If I ever start using VS 2008 maybe I'll remember this. But I
did give this disclaimer:

"Actually, I didn't know for a fact that it worked in C#, but I'll take your
word for it."
 
Jeff Johnson said:
Ah, Lambda. If I ever start using VS 2008 maybe I'll remember this. But I
did give this disclaimer:

I'd suggest giving it a go, its completely changed the way I do things now.
I thought it was just something that would be used on the odd occasion but
it's use crops up all the time. It does depend on the app, I had one app
where I could hardly find a use for it and another where it seemed to be in
every second function.

Michael
 
Back
Top