Common method for outputting arrays and lists of any type

In unit tests I might want to output the results of a returned list of any type. Instead of writing a new method for each type, here are some techniques with thanks to:

http://stackoverflow.com/questions/9655262/common-method-for-printing-arrays-and-lists-of-any-types

Using Join

Split is a useful function, here is the reverse Join

int[] actual = new int[] {1,2,3}

string actual = new string[] {“one”, “two”, “three”}

TestContext.WriteLine(string.Join(“, “, actual));

 

Using Generics

public void PrintCollection<T>(IEnumerable<T> col)
{
foreach (var item in col) TestContext.WriteLine(item);
}

 

Using ForEach(Action a)

http://msdn.microsoft.com/en-us/library/bwabdf9z(v=vs.110).aspx

[TestMethod()]
publicvoid AListTest()
{
List<string> target = newList<string>();
target.ForEach(PrintCollection2);
}

privatevoid PrintCollection2(string s)
{
TestContext.WriteLine(s);
}

 

 

 

Advertisements

Writing C# as a VB.Net programmer

Comparisons have been written before.

http://www.harding.edu/fmccown/vbnet_csharp_comparison.html

Differences

VB.Net C# Notes
OrElse || .
Public public Note casing
If public is excluded VB.Net assumes Public. In C# assumes private.
Property MyString As String string MyString;
Property MyString As String var MyString = “Hello World”; In c# var is used to infer
Sub Main static void Main(string[] args)
int + double = double

How to show XML Comments when using an assembly dll in another project

In the assembly to be redistributed ensure that

VB.Net

Properties > Compile > “Generate XML documentation file” is ticked

Build the project. When copying the dll to the place where you wish to use it, also copy the xml file

 

C#

Properties > Build > Output > “XML documentation file” tick

This may create a lot of warnings.

“Missing XML comment for publicly visible type or member ””

To suppress these XML comment missing warnings, then on same page “Suppress Warnings” add 1591