Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

22 August 2010

I CAN HAZ MONO

To partially cure my boredom, I downloaded the Mono framework, a piece of software that allows cross platform programs to be written in Microsoft's C#. Installation was decently straightforward; install the program from an installer in a disk image and you are ready to code. For some reason, the GUI toolkits did not install correctly (but they are on my hard disk), and because I did not look into the problem, I was not able to play with GUI-based applications. Maybe everything will install correctly on my Linux box. I will finally get to use it tomorrow when I go to Massachusetts!

Here is the basic Hello World program:

using System;


public class HelloWorld
{
static public void Main()
{
Console.WriteLine("Hello MonoWorld!");
}
}

But the WinForms and GTK# based GUI applications failed to compile, sadly.

WinForms:

using System;
using System.Windows.Forms;


public class HelloWorld : Form
{
static public void Main()
{
Application.Run(new HelloWorld());
}
public HelloWorld()
{
Text = "Hello MonoWorld";
}
}

GTK#:

using Gtk;
using System;


class Hello
{
static void Main()
{
Application.Init();
Window window = new Window("hi");
window.Show();
Application.Run();
}
}

Feedback on my first C# post: Interestingly, I received quite a bit of feedback on my journey with C# all on Buzz. It evolved into quite an interesting thread. [Link]

And finally, here is a bit of programming/compsci humor:


Nope, I do not have mono(nucleosis). :P

11 August 2010

Adventures of a Music Note: C#

For the past two days or so, I began my adventures learning a Microsoft-centric programming language called C#. (Yes, this means I have to use Windows 7 instead of Linux on my QuadBox.) It seems relatively useful to know, and it's always nice to know more programming languages. Right now I'm still working through the basics and getting to know the language. Without further ado I shall present two niceties.

Append an @ before a keyword to use it as a variable name:

int @new = 5;
Console.WriteLine(@new); // outputs 5

Create nullable booleans! The book just put this in the beginning to show that such a feature exists, but goes into more detail later. It's useful if a trinary boolean system is required.

Boolean? married = null;
if (married == true)
{
Console.WriteLine("married = true");
}
else if (married == false)
{
Console.WriteLine("married = false");
}
else
{
Console.WriteLine("married = null");
}

The code above outputs married = null

That's all for now. Tune in again!