Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How come Linq functions are available on a variable which can be of a type string

Please help me with this question. I thought that Linq works on a collection or an array. How come Linq works on a single string variable.

like image 921
sly_Chandan Avatar asked Dec 03 '10 07:12

sly_Chandan


1 Answers

LINQ To Objects works primarily on IEnumerable<T>, the canonical interface for sequences of a specified type. System.String implements IEnumerable<char>, meaning that it can be viewed as a sequence of characters.

[SerializableAttribute]
[ComVisibleAttribute(true)]
public sealed class String : IComparable, 
    ICloneable, IConvertible, IComparable<string>, IEnumerable<char>, 
    IEnumerable, IEquatable<string> 

LINQ itself is a pattern, more than anything. It's not restricted to IEnumerable<T> or IQueryable<T> for that matter.

like image 112
Ani Avatar answered Nov 26 '22 05:11

Ani