System.Data.DataRowCollection Extension Methods

DataRowCollection.AsEnumerable Method

A DataRowCollection extension method that converts the @this to an IEnumerable.

Syntax

IEnumerable<DataRow> AsEnumerable(DataRowCollection @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System.Collections.Generic;
 using System.Data;
 using System.Linq;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_Data_DataRowCollection_AsEnumerable
     {
         [TestMethod]
         public void AsEnumerable()
         {
             var dt = new DataTable();
             dt.Columns.Add("Fizz");
             dt.Rows.Add("Buzz");
 
             // Type
             DataRowCollection @this = dt.Rows;
 
             // Examples
             IEnumerable<DataRow> value = @this.AsEnumerable(); // DataRowCollection is now a IEnumerable<DataRow>.
 
             // Unit Test
             Assert.AreEqual("Buzz", value.First()["Fizz"]);
         }
     }
 }
                

DataRowCollection.ToList Method

A DataRowCollection extension method that converts the @this to a list.

Syntax

List<DataRow> ToList(DataRowCollection @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System.Collections.Generic;
 using System.Data;
 using System.Linq;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_Data_DataRowCollection_ToList
     {
         [TestMethod]
         public void ToList()
         {
             var dt = new DataTable();
             dt.Columns.Add("Fizz");
             dt.Rows.Add("Buzz");
 
             // Type
             DataRowCollection @this = dt.Rows;
 
             // Examples
             List<DataRow> value = @this.ToList(); // DataRowCollection is now a List<DataRow>.
 
             // Unit Test
             Assert.AreEqual("Buzz", value.First()["Fizz"]);
         }
     }
 }
                

Last edited Nov 23, 2013 at 6:52 PM by Jonathan_Magnan, version 1