Warning: strstr() expects parameter 1 to be string, array given in /f2/f9blog/public/wp-content/plugins/autoblogged/ab-functions.php on line 49
program - F9 Group Marketing and Technology Blog

F9 Group Marketing and Technology Blog

Marketing, Technology, and current news at http://www.f9group.com/

Entries Tagged ‘program’

Iterate Over IDictionary

To iterate over an IDictionary<x,y> interface, use the KeyValuePair<x,y> structure.  Following is a simple example: using System; using System.Collections.Generic; namespace CSharp411 { class Program { static void Main( string[] args ) { Related posts: Multiple Generic IEnumerable<T> Sort C# Array in Descending/Reverse Order Clean/Strip/Remove Binary Characters from C# String

Share and Enjoy:
  • Digg
  • Google
  • del.icio.us
  • Technorati
  • Facebook
  • MySpace
  • TwitThis
  • Blogsvine
  • description
  • E-mail this story to a friend!
  • Ping.fm
  • Print this article!
  • Slashdot
  • Yahoo! Buzz

How to Launch a Process Synchronously

Most developers use the Process.Start static method to run an external application from within C# code.  The Start method launches the external process asynchronously, meaning that your C# code continues executing and does not wait for the process to finish. But occasionally you may wish to halt your program and wait for the external process to Related posts: The Proper Way to Show the Wait Cursor Convert Between Synchronous and Asynchronous Close All Forms in an Application in a Thread-Safe Manner

Share and Enjoy:
  • Digg
  • Google
  • del.icio.us
  • Technorati
  • Facebook
  • MySpace
  • TwitThis
  • Blogsvine
  • description
  • E-mail this story to a friend!
  • Ping.fm
  • Print this article!
  • Slashdot
  • Yahoo! Buzz

C# Read String Line by Line

It’s easy to read a string one line at a time.  Here is a console program that demonstrates how: using System; using System.IO; namespace CSharp411 { class Program { static void Main( string[] args ) {

Share and Enjoy:
  • Digg
  • Google
  • del.icio.us
  • Technorati
  • Facebook
  • MySpace
  • TwitThis
  • Blogsvine
  • description
  • E-mail this story to a friend!
  • Ping.fm
  • Print this article!
  • Slashdot
  • Yahoo! Buzz

C# Read Text File Line-by-Line

Here is the code to read a text file from disk one line at a time into a string.  This code ensures the file exists and properly closes the file if an exception occurs. using System; using System.IO; namespace CSharp411 { class Program { static

Share and Enjoy:
  • Digg
  • Google
  • del.icio.us
  • Technorati
  • Facebook
  • MySpace
  • TwitThis
  • Blogsvine
  • description
  • E-mail this story to a friend!
  • Ping.fm
  • Print this article!
  • Slashdot
  • Yahoo! Buzz

Find the Root of a C# Hierarchy

Many objects in .NET are stored in a hierarchy.  For example: controls, files and folders, and anything you would normally display in a tree view.  There are many different algorithms for finding the root of a hierarchy.  Here is one of them: public MyObject GetRoot() {     // start with this as root     MyObject root = this;     // get the parent     MyObject parent = this.Parent;     // keep going until no more parents     while (parent != null)     {         // save the parent         root = parent;         // get the parent of the parent         parent = parent.Parent;     }     return root; } Sample Program Here is a simple console program that demonstrates this.  Note that the function to get the root is a method GetRoot() instead of a Root property.  Making it a method instead of a property implies that it must be calculated each time, similar to how the .NET Control class has a FindForm() method. using System; using System.Collections.Generic; namespace CSharp411 {     class Program     {         static void Main( string[] args )         {             MyObject a = new MyObject( “a” );             MyObject b = new MyObject( “b” );             MyObject c = new MyObject( “c” );             MyObject d = new MyObject( “d” );             a.AddChild( b );             b.AddChild( c );             c.AddChild( d );             Write( a );             Write( b );             Write( c );             Write( d );             Console.ReadLine();         }         static void Write( MyObject obj )         {             string objName = obj.Name;             MyObject parent = obj.Parent;             string parentName = parent == null ? “none” : parent.Name;             MyObject root = obj.GetRoot();             string rootName = root == null

Share and Enjoy:
  • Digg
  • Google
  • del.icio.us
  • Technorati
  • Facebook
  • MySpace
  • TwitThis
  • Blogsvine
  • description
  • E-mail this story to a friend!
  • Ping.fm
  • Print this article!
  • Slashdot
  • Yahoo! Buzz