Monday, 16 September 2013

DOTNET CSHARP LINQ EXAMPLES - K MANOHAR GOUD ONLINE IT TRAINER DEVELOPER - 9866550012

9866550012



Reading a Text File from LINQ


C#
var query =
        from line in File.ReadAllLines(filePath)
        let customerRecord = line.Split(',')
        select new Customer()
            {
                Firstname = customerRecord[0],
                Lastname = customerRecord[1],
                JobTitle = customerRecord[2],
                City = customerRecord[3],
                Country = customerRecord[4]
            };
foreach (var item in query)
{
    Console.WriteLine("{0}, {1}, {2}, {3}, {4}",
        item.Firstname, item.Lastname, item.JobTitle, item.City, item.Country);
}


VB .NET
Dim
query = From line In File.ReadAllLines("C:\temp\Sample.txt") _Let sampleRecord = line.Split(","c) _Select New SampleFile()

For Each item In query
        Console.WriteLine(

"{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", _
           item.Column1, item.Column2, item.Column3, item.Column4, item.Column5, _
           item.Column6, item.Column7, item.Column8, item.Column9, item.Column10)
Next







No comments:

Post a Comment