C # Syntax and Linq, IQueryable

This is a SYNTAX question for C # and NOT about how we call / use IQueryable

Can someone explain to me:

We have this declaration (System.Linq):

public static double Average<TSource>(this IQueryable<TSource> source,
                                      Expression<Func<TSource, int>> selector)

and call the mean

double average = fruits.AsQueryable().Average(s => s.Length);

I understand how to call the Mean value and all similar static methods of IQueryable, but I do not understand the syntax of the declaration.

public static double Average<TSource>(this IQueryable<TSource> source,
                                      Expression<Func<TSource, int>> selector)

Which means <TSource>in as well . Average<TSource>( this IQueryable<TSource> source

since only one parameter passes when we call it, and the actual lambda expression (s => s.Length);

Thanks in advance.

+3
source share
6 answers

<TSource> - , . , LINQ.

this IQueryable<TSource> source

:

  • this ,
  • IQueryable<TSource>
  • source -

, , , .

query.Average(s => s.Length)

Queryable.Average(query, s => s.Length)
+6

( this), , IQueryable<TSource>, TSource .

,

+1

TSource - , . , s.

0

Average<TSource>, . ( ).

this IQueryable<TSource> source, . . Linq Average IQueryable .

0
  • <TSource> - .
  • this IQueryable<TSource> source , . # 2.0 , , , , .
0

<X> , .

X add<X>(X a, X b){return a + b;}

int a = 1;
int b = 2;
int c = add<int>(a,b);

string d = "hello ";
string e = "world";
string f = add<string>(c,d);

:

string putinsidestars(this string x){
  return "*" + x + "*";
}

string foo = "bar";
string z = foo.putinsidestars();
// z now contains *bar*
0

Source: https://habr.com/ru/post/1745961/


All Articles