Test written from mobility now.

How to use Regular expression multiline option

using System;
using System.Text.RegularExpressions;

namespace testregex
{
 class Class1
 {
  [STAThread]
  static void Main(string[] args)
  {
   string multistr="aaaaa\r\nbbbb\r\nccccc\r\nccbbb";
   Console.WriteLine(multistr);

   Regex r = new Regex("^b+\r$",RegexOptions.Multiline);
   Match m= r.Match(multistr);
   Console.WriteLine(m.ToString());	
  }
 }
}

result

aaaaa
bbbb
ccccc
ccbbb

bbbb

How to foreach for Hashtable

How to Get Instance for DirectoryEntry Class
and Use Property Keys

using System;
using System.Collections;

namespace test3
{
 class Class1
 {
  [STAThread]
   static void Main(string[] args)
	{
	 Hashtable ht = new Hashtable();
	 ht.Add("America","Washington");
	 ht.Add("Chinese","Beijing");
	 ht.Add("Italian","Rome");
	 ht.Add("Japanese","Tokyo");
	 foreach ( DictionaryEntry dCapital in ht ) 
	 {
	  Console.WriteLine(dCapital.Key +" "+ dCapital.Value);
	 }
	 Console.WriteLine("");
	 foreach (string country in ht.Keys) 
	 {
	  Console.WriteLine(country +" "+ ht[country]);
	 }
	}
 }
}

result

America : Washington
Japanese : Tokyo
Italian : Rome
Chinese : Beijing

America : Washington
Japanese : Tokyo
Italian : Rome
Chinese : Beijing

It is not called in order of registration.

How to use bit field

using System;

namespace test2
{
 [FlagsAttribute] 
  enum MyColor : short 
  {
    Black = 0,
    Red	  = 1,
    Green = 2,
    Blue  = 4
  };
  class Class1
  {
   [STAThread]
   static void Main(string[] args)
   {
    short BlackOnly = (short)MyColor.Black;
    Console.WriteLine(BlackOnly);
    short BlackRed = (short)MyColor.Black|
                     (short)MyColor.Red;
    Console.WriteLine(BlackRed);
    short All=(short)MyColor.Black|
              (short)MyColor.Red|
              (short)MyColor.Green|
              (short)MyColor.Blue;
    Console.WriteLine(All);
   }
  }
}

result

0
1
7

2D array to 1D array

namespace array2dto1d
{
class Class1
 {
   [STAThread]
    static void Main(string args)
    {
//	int[,] data2Darray={ {1,2,3},
//	                     {4,5,6},
//	                     {7,8,9},
//	                     {10,11,12}
//			   };
//	int[,] data2Darray = {
//		              {1,3,2,3},
//			      {7,5,7,9},
//			      {1,4,6,8}
//  			     };
//	int[,] data2Darray={ {1,2,3},
// 		             {4,5,6},
//			     {7,8,9}
//			   };
        int[,] data2Darray={ {1,2,3,4},
	  	             {5,6,7,8},
		             {9,10,11,12},
		             {13,14,15,16}
		           };
	arraytest2(data2Darray);
        arraytest(data2Darray);
     }

	/// 
	/// for cube matrix
	/// 
	/// 
	/// 1,2,3
	///          4,5,6
	///          7,8,9
	///            ↓
	///          2,4,7,2,5,8,3,6,9
        ///
	public static void arraytest2(int[,]data2Darray)
	{
	  int dataArray = new int[data2Darray.Length];
	  for(int i=0;i

result

data[0] = 1
data[1] = 5
data[2] = 9
data[3] = 13
data[4] = 2
data[5] = 6
data[6] = 10
data[7] = 14
data[8] = 3
data[9] = 7
data[10] = 11
data[11] = 15
data[12] = 4
data[13] = 8
data[14] = 12
data[15] = 16
行=4
列=4
data[0] = 1
data[1] = 5
data[2] = 9
data[3] = 13
data[4] = 2
data[5] = 6
data[6] = 10
data[7] = 14
data[8] = 3
data[9] = 7
data[10] = 11
data[11] = 15
data[12] = 4
data[13] = 8
data[14] = 12
data[15] = 16