0
Can someone explain this code to me ?
I found this code somewhere in sololearn and I just wanted to know how it works. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { string input = Console.ReadLine(); string output = new String(input.Where(c => Char.IsWhiteSpace(c) || Char.IsLetterOrDigit(c)).ToArray()); Console.Write(output); } } }
1 Answer
+ 1
This is using LINQ and lambda expressions. Basically this is filtering the data. Itâs like SQL for collections.
c is just a variable name representing one item in the collection. In this case the colletion is an array of chars.
Simliar to how youâd do this in a foreach statement.
foreach(var c in input)
{...}
https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.where?view=netframework-4.8



