Home About

February 9th, 2009

C# Hello World for LINQ on Mono - 0

If you are up to date with your Ubuntu distribution you will be using Mono 1.9.1 which has support for C# LINQ build in. Enabling it is as easy as adding “using System.Linq” to your project. The following code snippet is the LINQ equivalent of a “Hello World” application:

    using System;
    using System.Linq;

    class MainClass

        public static void Main(string[] args)
            String[] world = { "Hello World", "Hello Mars" , "Hello Venus" };
            var rightOne = from s in world where s.EndsWith("World") select s;
            foreach(string planet in rightOne)

The first time I tried compiling it, MonoDevelop gave me the following error:

An implementation of `Where’ query expression pattern could not be found. Are you missing `System.Linq’ using directive or `System.Core.dll’ assembly reference?(CS1935)]

You can solve this by ensuring that you have added “System.Core” as a reference to your solution/project. You can do this by right clicking “References” in the “Solution Panel” and selecting “Edit References”.

Be Sociable, Share!

Tags: ,

Comments are closed.

Most popular
Recent Comments
  • ARS: great plugin! I love it! but, it will be so nice if you can add attribute ‘title’ as one of...
  • Nelson: Saved me from doing it myself. Good article.
  • andy: i am currently playing taiwanese server wow in 奈辛瓦里(PVP) and i would like to realm transfer to somewhere there...
  • berties: any english speaking playing on a taiwanese server?
  • web application development: has C# search volume really so constant over the years? really surprising.