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#
    F# FEBRUARY 2010 RELEASE

    A look at IEnumerator and IEnumerable interfaces in C#

    There are two interfaces which are at the base of many classes and the logic we use daily, to implement .Net based applications. These two interfaces are closely related to each other and provide a fuctionality that makes working with a Collection, fun. These are interfaces are IEnumerator and IEnumerable

    Both of these interfaces work together. We need a class to implement IEnumerator interface, which provides implementations for Current property , MoveNext() and Reset() methods like below.

    First, consider a class Job, around which all the logic will surround

        public class Job
        {
            public Job(string _jobName, int _duration)
            {
                this.jobName = _jobName;
                this.duration = _duration;
            }
    
            public string jobName;
            public int duration;
        }
    

    Now, we have class that implements IEnumerator with an underlying array of Job objects:

        class JobsList : IEnumerator
        {
            Job[] jobs;
            int position = -1;
    
            public JobsList(Job[] _jobs)
            {
                jobs = _jobs;
            }
    
            #region IEnumerator Members
    
            public object Current
            {
                get
                {
                    try
                    {
                        return jobs[position];
                    }
                    catch (IndexOutOfRangeException)
                    {
                        throw new InvalidOperationException();
                    }
                }
            }
    
            public bool MoveNext()
            {
                position++;
                return (position < jobs.Length);
            }
    
            public void Reset()
            {
                position = -1;
            }
    
            #endregion
        }
    

    Now consider another class Jobs. This class implements IEnumerable interface method GetEnumerator() returns IEnummerator object which holds indexed access to underlying array of Job objects as follows:

        class Jobs : IEnumerable
        {
            #region IEnumerable Members
    
            Job[] jobs;
    
            public Jobs(Job[] _jobsArray)
            {
                jobs = new Job[_jobsArray.Length];
    
                for (int i = 0; i < _jobsArray.Length; i++)
                {
                    jobs[i] = _jobsArray[i];
                }
            }
    
            public IEnumerator GetEnumerator()
            {
                return new JobsList(jobs);
            }
    
            #endregion
        }
    

    This is how now can use and manipulate our newly created IEnumerator object

            static void Main(string[] args)
            {
                // create new Job Array
                Job[] jobsArray = 
                     new Job[] { new Job("JobA", 1), new Job("JobB", 2), new Job("JobC", 3) };
    
                // // create new IEnumerable 
                Jobs jobs = new Jobs(jobsArray);
    
                // // create new IEnumerator
                IEnumerator jobsEnummerator = jobs.GetEnumerator();
    
                // following are some you can work over 
                // ways we can works over IEnumerator object
                while (jobsEnummerator.MoveNext())
                { }
    
                //  or using foreach
                foreach (Job job in jobs)
                { }
            }