Using Linq to Objects in C#

by a Guest on October 21, 2010 0 Comments

This tutorial was created with Microsoft Visual Studio .NET 2008.

In this tutorial, we will be looking at using LINQ to Objects. We will be creating a Windows Forms Application that will first define an array of numbers, and then we will use LINQ to Objects to interact with this collection of numbers. We will create buttons to display the results of calculations of the numbers, demonstrating the built-in functions of LINQ, that we can perform on most any collection.

We will start by designing our form with Four buttons and a label. The first button will be to display all the numbers in our array, which we will hard-code for this example. The label will be to show the results of our functions, and then the other three buttons we will use for LINQ functions.

We will also implement a StatusStrip control to make use of the label within ...

read more

Lorem Ipsum Generator in C#

by a Guest on October 21, 2010 0 Comments

This class will create a Lorem Ipsum generator that can be used to create the famous "Lorem ipsum dolor sit amet" used to dummy text.

using System;
using System.Text;
 
/// <summary>
/// Lorem Ipsum generator class for C#
/// </summary>
public class Ipsum
{
  private string[] words = new string[] { "consetetur", "sadipscing", "elitr", "sed", "diam", "nonumy", "eirmod",
    "tempor", "invidunt", "ut", "labore", "et", "dolore", "magna", "aliquyam", "erat", "sed", "diam", "voluptua",
    "at", "vero", "eos", "et", "accusam", "et", "justo", "duo", "dolores", "et", "ea", "rebum", "stet", "clita",
    "kasd", "gubergren", "no", "sea", "takimata", "sanctus", "est", "lorem", "ipsum", "dolor", "sit", "amet",
    "lorem", "ipsum", "dolor", "sit", "amet", "consetetur", "sadipscing", "elitr", "sed", "diam", "nonumy", "eirmod",
    "tempor", "invidunt", "ut", "labore", "et", "dolore", "magna", "aliquyam", "erat", "sed", "diam", "voluptua",
    "at", "vero", "eos", "et", "accusam", "et", "justo", "duo", "dolores", "et", "ea", "rebum", "stet", "clita",
    "kasd", "gubergren", "no", "sea", "takimata", "sanctus", "est", "lorem", "ipsum", "dolor", "sit", "amet",
    "lorem", "ipsum", "dolor", "sit", "amet", "consetetur", "sadipscing", "elitr", "sed ...

read more

How to Obtain Current Application Directory in C#

by a Guest on October 21, 2010 0 Comments

From time to time you may need to access a file within the current application folder. .Net provides a property that is set to the absolute path to the application executable, and a method can be used to extract the folder name.

using System.IO;
using System.Windows.Forms;
 
string appPath = Path.GetDirectoryName(Application.ExecutablePath);

Note: Console Application project types will have to manually add a reference to the System.Windows.Forms assembly for the Application object to be exposed.

View the original article here

File Directory Listing in C#

by a Guest on October 21, 2010 0 Comments

This little snippet will process a directory and get a list of all the files in the directory, returning them as a StringBuilder object:

        using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
 
namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
      StringBuilder dirList = directoryListing("C:\\Inetpub", "");
      Console.WriteLine(dirList.ToString());
    }
 
    static StringBuilder directoryListing(string path, string indent)
    {
      StringBuilder result = new StringBuilder();
      DirectoryInfo di = new DirectoryInfo(path);
      DirectoryInfo[] rgDirs = di.GetDirectories();
 
      foreach (DirectoryInfo dir in rgDirs)
      {
        result.AppendLine(indent + dir.Name);
        result.Append(directoryListing(path, indent + "..").ToString());
      }
      return result;
    }
  }
}

View the original article here

Using Regular Expression in C# to Check Email Address Validity

by a Guest on October 21, 2010 0 Comments

Regular expressions are special strings that are used to describe a search pattern. They can be used for data validation, data processing and pattern matching.

Regular Expressions (regex for short) are language and platform independent so an expression for Perl will work on PHP and C#. Regex start with a caret (^) character and end with a dollar ($) symbol. The text in between these two characters is used to match a string.

Regular expressions in C# are defined within the System.Text.RegularExpressions namespace which provides a Regex class. When instantiating the class you need to pass the expression string to the constructor. We have used a verbatim string for the regex as it makes the regex easier if you don't have to escape forward slashes.

In this example we test two strings to see if they contain a valid email address. The emailRegex will match any valid email address ...

read more

Testing C# Code Performance Speed

by a Guest on October 21, 2010 0 Comments

Programming with C#, as in a lot of languages, gives an infinite amount of ways to write applications. All the different programming pratices can vary your application's speed and efficiency. Determening which coding techniques are faster is an essential skill.

The algorithm to test out fast and efficient C# source code run is:

-> Initialize variables needed

-> Declare a System.Diagonistic.StopWatch varible.

-> Include this line before starting the test: [StopWatch variable].Start();

-> Setup a for loop with the code to be tested inside

-> The amount of trials should be set up in such a way that the total execute time lasts an appropriate duration

-> Execute this line to stop the StopWatch: [StopWatch variable].Stop();

-> Initialize a new TimeSpan variable with: TimeSpan span = new TimeSpan([StopWatch variable].ElapsedTicks);

-> The span variable has the amount of time the source took to run

An optional part is to divide the time it ...

read more

Nivo Slider is One Awesome jQuery Image Slider

by a Guest on October 3, 2010 0 Comments

Nivo Slider is the most awesome jQuery image slider, manual and auto slide transaction with cool effect. jqFancyTransitions is easy-to-use jQuery plugin for displaying your photos as slideshow with fancy transition effects.

Nivo Slider Home Page

Will Microsoft SQL Server Ever Pass Oracle?

by a Guest on August 16, 2010 0 Comments

Do you think that Microsoft SQL Server will ever pass Oracle?

Page 1 of 1.

Post categories

Post archives