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

System.Data.DataColumnCollection Extension Methods

DataColumnCollection.AddRange Method

A DataColumnCollection extension method that adds a range of columns with the specified values.

Syntax

void AddRange(DataColumnCollection @this,string[] values)

Parameters

@this
The @this to act on.
values
A variable-length parameters list containing values.

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.Data;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_Data_DataColumnCollection_AddRange
     {
         [TestMethod]
         public void AddRange()
         {
             var dt = new DataTable();
 
             // Type
             DataColumnCollection @this = dt.Columns;
 
             // Examples
             @this.AddRange("Fizz", "Buzz"); // Add "Fizz" and "Buzz" column.
 
             // Unit Test
             Assert.AreEqual(2, @this.Count);
         }
     }
 }
                

DataColumnCollection.AsEnumerable Method

A DataColumnCollection extension method that enumerables the given object.

Syntax

IEnumerable<DataColumn> AsEnumerable(DataColumnCollection @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_DataColumnCollection_AsEnumerable
     {
         [TestMethod]
         public void AsEnumerable()
         {
             var dt = new DataTable();
             dt.Columns.Add("Fizz");
 
             // Type
             DataColumnCollection @this = dt.Columns;
 
             // Examples
             IEnumerable<DataColumn> value = @this.AsEnumerable(); // DataColumnCollection is now a IEnumerable<DataColumn>.
 
             // Unit Test
             Assert.AreEqual("Fizz", value.First().ColumnName);
         }
     }
 }
                

DataColumnCollection.ToList Method

A DataColumnCollection extension method that converts an obj to a list.

Syntax

List<DataColumn> ToList(DataColumnCollection @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_DataColumnCollection_ToList
     {
         [TestMethod]
         public void ToList()
         {
             var dt = new DataTable();
             dt.Columns.Add("Fizz");
 
             // Type
             DataColumnCollection @this = dt.Columns;
 
             // Examples
             List<DataColumn> value = @this.ToList(); // DataColumnCollection is now a List<DataColumn>.
 
             // Unit Test
             Assert.AreEqual("Fizz", value.First().ColumnName);
         }
     }
 }
                

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