Post

Multiply Collection Elements

In .NET framework, Visual Basic on September 7, 2011 by jwavila Tagged: , , ,

Another post on the MSDN Forums, another idea for a blog. The title of the post was “Multiplying the Contents of an Array”. The OP wanted to know if there was a VB.NET equivalent to an Excel formula such as “=product(A1:A30)” , which would multiply all the elements in an array together.

A few Forum members responded with some usual and not so usual solutions: from a basic loop to an extension method. While .NET has some obvious built-in methods such as Sum and Average, these do not include one for the Product of all the elements of a collection. At least not an obvious one!

Read More »

Post

DataTable to CSV

In .NET framework, Visual Basic on August 15, 2011 by jwavila Tagged: , , , ,

There are many examples (and ways) available to save data from a DataTable to a csv TextFile. The vast majority utilize some type of loop to iterate through the rows and either  a string variable or a StringBuilder object to create the delimited line of text to save to the file.

In this article I’m going to show a slightly different approach.

Read More »

Post

Lambda Expressions – I thought I was done

In .NET framework, Visual Basic on August 2, 2011 by jwavila Tagged: , ,

Since the time I “finished” this series of articles on Lambda Expressions, there were a couple of more questions asked on the Forums that lent themselves well to using a Lambda Expression. I thought I would discuss those here to provide some more ideas on the use of LEs. I’ve also included a solution using a LINQ query, since they go hand-in-hand.

Read More »

Post

Lambda Expressions – Final(ly)

In .NET framework, Visual Basic on July 29, 2011 by jwavila Tagged: ,

This is the final part on the series about Lambda Expressions. I thought I would end it with an explanation of the motivation to write a little about LEs.  As with many of the articles I’ve written, the inspiration comes from what I think is an interesting solution to a problem posted on the Forums.

If you’d like a short description of the posted question and an extremely ingenious use of Lambda Expressions to solve it… Read More »

Post

Lambda Expressions – Part 3

In .NET framework, Visual Basic on July 28, 2011 by jwavila Tagged: ,

In the first two parts of this series, some examples of LEs were shown. In this part we will review some more examples. Note that these are coded in VS2010. The reason being one of the examples uses a Sub instead of a Function, and the Sub type LE is not available in VS2008. I have also included some of the info from MSDN on LEs, specifically the discussion about the LE syntax and how it differs from a standard function or subroutine.

So without further delay, let’s get on with it. Read More »

Post

Lambda Expressions – Part 2

In .NET framework, Visual Basic on July 27, 2011 by jwavila Tagged: , ,

In the first part of this series  we used some simple LEs to query a List(Of String). As you saw in the examples LEs can be a powerful tool to not only extract the data, but also shorten your code.

Part 2 will expand on what was learned by applying the same principles to a List(Of T) containing custom objects. Note that the code for this article was written in VS2010. The only reason being I’m lazy and wanted to utilize the auto-implemented properties new to Visual Basic in 2010. If you will be working in VS2008, you’ll need to add the Get and Set code blocks for the properties.

Read More »

Post

Lambda Expressions: An Intro

In .NET framework, Visual Basic on July 26, 2011 by jwavila Tagged: ,

Lambda Expressions (also known as Inline Functions) can be a powerful tool to use. So what exactly are Lambda Expressions? I found many different definitions and descriptions, so rather than try to provide one here, I’ll leave it up to you to do a little research and come up with your own idea. Also to get an idea of the power and flexibility they offer.

The purpose of this first article (there will be more – how many is unknown at this time) is to show some simple examples utilizing a List(Of T). Lambda Expressions are essential in many of the native List methods, such as Find, FindAll, etc. Read More »

Post

Letter Scramble

In .NET framework, Visual Basic on July 19, 2011 by jwavila Tagged: ,

A post on the Forums asked how to select a random word from an array, then reverse the letters.  Pretty simple using the Reverse  method.

I decided to take it one step further and rearrange the letters randomly. After completing the task, I searched the Internet for other examples. In my opinion, the solution below is more efficient than others I found. Read More »

Follow

Get every new post delivered to your Inbox.