bool matches = Regex.IsMatch( input, regex );
.NET and Mono are actually a collection of libraries that form a framework which allows you, the programmer, to write the logic of your application. I can call one line of code to do input validation on a string which saves you possibly hours of time. Things like Input validation, network communication, file reading and writing, text encoding, regular expressions, formatting, XML Parsing, LDAP Access, remoting, and GUI development are reduced to just a few lines of code compared to possibly hundreds.
Next: Gtk# Application
Next we’ll demonstrate development of a Gtk# application that runs on both Linux and Windows. Using the brand new MonoDevelop, this makes it fairly quick. We’ll do the same application, with two textboxes, and it will update the result label in real time (each character you type will verify the regex).
So lets open MonoDevelop and start a new Gtk# project, call it whatever you want. After the project is created you’ll see a MyWindow.cs: open that and replace everything with the below code:
using System; using Gtk; using System.Text; using System.Text.RegularExpressions; public class MyWindow : Window { private VBox vBox; private HBox hbox1; private HBox hbox2; private HBox hbox3; private Entry txtInput; private Entry txtRegex; private Entry txtResult; private Label lblLeft1; private Label lblLeft2; private Label lblLeft3; public MyWindow () : base ("Linux.ars") { this.SetDefaultSize (400, 300); this.DeleteEvent += new DeleteEventHandler (OnMyWindowDelete); /* Create a vertical panel, each with horizontal panels,*/ /* the left side is the label and the right side is the textbox */ vBox = new VBox(false, 3); hbox1 = new HBox(false, 2); hbox2 = new HBox(false, 2); hbox3 = new HBox(false, 2); txtInput = new Entry(); txtRegex = new Entry(); txtResult = new Entry(); lblLeft1 = new Label(); lblLeft2 = new Label(); lblLeft3 = new Label(); // Disable editing of the result box txtResult.Editable = false;
// If anything changes in the text boxes, // call this function (These are event handler delegates) txtRegex.Changed += new EventHandler(ChangedSomething); txtInput.Changed += new EventHandler(ChangedSomething); // Set the text of the labels on the left lblLeft1.Text = "Input String:"; lblLeft2.Text = "Regular Expression:"; lblLeft3.Text = "Result:"; // Make them the same size lblLeft1.SetSizeRequest(150, 20); lblLeft2.SetSizeRequest(150, 20); lblLeft3.SetSizeRequest(150, 20); // Align the text to the right lblLeft1.SetAlignment( 1, (float)0.5 ); lblLeft2.SetAlignment( 1, (float)0.5 ); lblLeft3.SetAlignment( 1, (float)0.5 ); // Now we add the controls to the panels hbox1.PackStart(lblLeft1, true, true, 6); hbox1.PackEnd(txtInput, true, true, 6); hbox2.PackStart(lblLeft2, true, true, 6); hbox2.PackEnd(txtRegex, true, true, 6); hbox3.PackStart(lblLeft3, true, true, 6); hbox3.PackEnd(txtResult, true, true, 6); vBox.PackStart(hbox1, true, true, 0); vBox.PackStart(hbox2, true, true, 0); vBox.PackStart(hbox3, true, true, 0); // Set the window characteristics this.SetDefaultSize( 250, 80 ); this.Resizable = false; this.BorderWidth = 10; // Add the whole shebang to the window this.Add( vBox ); // Show everything this.ShowAll (); } void OnMyWindowDelete (object o, DeleteEventArgs args) { Application.Quit (); } void ChangedSomething(object o, EventArgs e) { // Get the text from the boxes // (this gets called after it's updated) String Input = txtInput.Text; String RegEx = txtRegex.Text; try { if( Regex.IsMatch(Input,RegEx) ) txtResult.Text = "Matches"; else txtResult.Text = "Does Not Match"; } catch(System.ArgumentException ae) { txtResult.Text = "Invalid Regular Expression"; } } }
Download the compiled binary: Here
The above code, should produce the result below (on Linux):

And on Windows:

Conclusion
As you can clearly see, Mono brings almost limitless possibilities in breaking down the barrier between desktops: a commercial software provider would target Mono and it would “just work” on all platforms that Mono supported. How is this different from Java? In my opinion Java makes things harder than it needs to be. For starters, enforced exception handling can’t auto-box/unbox primitive types and doesn’t support arbitrary length parameter lists String.Format() style.
The framework of Mono provides the ability to make a very tedious task in C/C++ almost trivial in C#. As the above example, RegEx, shows, it helps the programmer concentrate on the program itself, rather than the logic supporting the code.