Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / C#

C# Script: The Missing Puzzle Piece

Rate me:
Please Sign up or sign in to vote.
4.88/5 (184 votes)
6 Aug 2014MIT24 min read 1.3M   9.4K   531  
An article on a "scripting engine" for the C# language
using System;
using System.Windows.Forms;
using System.Threading;

namespace  CSScript
{
	class Ticker
	{
		const string usage = "Usage: tick.cs [seconds] ...\ncounts specified number of seconds (default is 5 sec). \n";

		static public void Main (string[] args)
		{
			if ((args.Length == 1 && (args[0] == "?" || args[0] == "/?" || args[0] == "-?" || args[0].ToLower() == "help")))
			{
				Console.WriteLine(usage);
			}
			else
			{
				int count = 5;
				if (args.Length != 0)
				{
					try
					{
						count = Convert.ToInt32(args[0]);
					}
					catch 
					{
						Console.WriteLine("Error: Invalid parameter");
					}
				}

				for (int i = 0; i < count; i++)
				{
					Console.WriteLine("tick");
					Thread.Sleep(1000);
				}
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Program Manager
Australia Australia
I was born in Ukraine. After completing the university degree worked there as a Research Chemist. Last 23 years I live in Australia where I've got my second qualification as a Software Engineer.

"I am the lucky one: I do enjoy what I am doing!"

Comments and Discussions