IS F# going to replace C#

One tool can not fit all needs.

  • Did Asp.Net MVC replace Asp.Net Forms ? No, both are used according to the project needs.
  • Did Vb.Net replace C# ? No, both provide almost same functionality and options but pull developers from both families. Vb and C.
  • Has WPF replaced, WinForms ? not yet, might in future.
  • Chris Smith’s on his Blog, says

    ” But just because you can write code in a new language doesn’t mean you should. So why use F#? Because being a functional language, F# makes writing some classes of programs much easier than its imperative cousins like C#. Parallel Programming and Language-Oriented Programming are two such domains that can be expressed easily in F#.

    If you’ve ever written a .NET application and found yourself fighting against the language to get your idea expressed, then perhaps F# is what you’ve been looking for.”

    F# is basically an functional language by its nature. The argument here could be more towards the style of programming rather than features a language may support.

    As per Eric Lipert answer to a similar topic ( my post was inpired to ) at stackoverflow, following things are to be considered before one thinks about using F# as the language of choice for a project.

  • F# cannot solve any problem C# could.
  • F# is a functional language, statically typed.
  • F# is a functional language that supports O-O-Programming
  • more information and references:

    Microsoft F# Developer Center
    F# at Microsoft Research

    And to:
    Learn F#
    download F#


    Using LINQ with Generic Dictionary in C#

    Here is quick example for how to manipulate a Dictionary object for some constraint and get a new Dictionary Object from that, using LINQ.

    Suppose we have a Dictionary as follows, which hold some of the values which might be null

     Dictionary<string, string> dictionaryWithNullValues = new Dictionary<string, string>();

    Adding Items to Dictionary

                dictionaryWithNullValues.Add("one", "one");
                dictionaryWithNullValues.Add("two", null);
                dictionaryWithNullValues.Add("three", "three");
                dictionaryWithNullValues.Add("four", "four");
                dictionaryWithNullValues.Add("five", null);

    Problem: we need a new dictionary object, almost same as the old one, but without the null values, from the old dictionary. Here is how we do this, using my beloved LINQ

       dictionaryWithoutNullValues =
       .Where(d => d.Value != null)
       .ToDictionary(s => s.Key, s => s.Value);

    To check the difference between both Dictionary Objects and verify, if this has worked, call the following properties on both old and new Dictionary Objects

    Console.WriteLine("OldDictionary Keys: " + dictionaryWithNullValues.Keys.Count);
    Console.WriteLine("OldDictionary Values: " + dictionaryWithNullValues.Values.Count);
    Console.WriteLine("NewDictionary Keys: " + dictionaryWithoutNullValues.Keys.Count);
    Console.WriteLine("NewDictionary Values: " + dictionaryWithoutNullValues.Values.Count);