This project has moved. For the latest updates, please go here.

System.Data.DataTableCollection Extension Methods

DataTableCollection.AsEnumerable Method

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

Syntax

IEnumerable<DataTable> AsEnumerable(DataTableCollection @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_DataTableCollection_AsEnumerable
     {
         [TestMethod]
         public void AsEnumerable()
         {
             var ds = new DataSet();
             ds.Tables.Add("Fizz");
 
             // Type
             DataTableCollection @this = ds.Tables;
 
             // Examples
             IEnumerable<DataTable> value = @this.AsEnumerable(); // DataTableCollection is now an IEnumerable.
 
             // Unit Test
             Assert.AreEqual("Fizz", value.First().TableName);
         }
     }
 }
                

DataTableCollection.ToList Method

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

Syntax

List<DataTable> ToList(DataTableCollection @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_DataTableCollection_ToList
     {
         [TestMethod]
         public void ToList()
         {
             var ds = new DataSet();
             ds.Tables.Add("Fizz");
 
             // Type
             DataTableCollection @this = ds.Tables;
 
             // Examples
             List<DataTable> value = @this.ToList(); // DataTableCollection is now a List<DataTable>
 
             // Unit Test
             Assert.AreEqual("Fizz", value.First().TableName);
         }
     }
 }
                

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