Click here to Skip to main content
15,886,578 members
Articles / Programming Languages / C#

AFP: Almost Functional Programming in C#: Part 2

Rate me:
Please Sign up or sign in to vote.
4.89/5 (4 votes)
6 Mar 2013CPOL20 min read 17.5K   142   12  
Putting the programming style to the test by using it in a multi-threaded server.
using System;

namespace StockTest
{
    public partial class Program
    {
        public Program()
        {
        }

        //void Run()
        //{
        //    var p = new Portfolio(new[] { 
        //            Tuple.Create("VOD LN", 100, "GBP"), 
        //            Tuple.Create("BP LN", 1000, "GBP"), 
        //            Tuple.Create("BMW GY", 200, "EUR"),
        //        });
        //    p.UpdateCurrencyRate("EUR", 1.0);
        //    p.UpdateCurrencyRate("GBP", 1.3);
        //    p.UpdateStockPrice("VOD LN", new Price(60.0, 61.0));
        //    p.UpdateStockPrice("BP LN", new Price(55.1, 55.2));
        //    p.UpdateStockPrice("BMW GY", new Price(155.1, 155.2));
        //    if (p.Result.IsReady) {
        //        Console.WriteLine(p.Result.Value.BuyPrice);
        //        Console.WriteLine(p.Result.Value.SellPrice);
        //    } else {
        //        Console.WriteLine("NOT READY");
        //    }
        //}

        static void Main(string[] args)
        {
            try {
                var program = new Program();
                program.Run();
            } catch (Exception ex) {
                Console.WriteLine("ERROR: {0}", ex.Message);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
New Zealand New Zealand
I am a senior software developer with almost 20 years of experience. I have extensive knowledge of C#, C++ and Assembly languages, working mainly on Windows and embedded systems. Outside of work I am interested in a wider variety of technologies, including learning 20 programming languages, developing Linux kernel drivers or advocating Functional Programming recently.

Comments and Discussions