3

I'm using C# 6.0 in VS Community

  1. Where event initializers removed from c# 6.0 & any idea why the code below doesn't work?

  2. Where can I get an updated list of not just latest features and what was recently removed from C# 6.0?

This doesn't compile for me. Specifically on line with 'Barking += (o, e)...'

    EventHandler<EventArgs> log = (o, e) => Console.Write("woof");
    var dog = new Dog()
    {
        Age = 3,
        Barking += (o, e) => Console.Write("woof");
    };

    class Dog
    {
        public void Bark() {
            if (Barking != null) {
                Barking(this,new EventArgs());
            }
        }
        public int Age { get; set; } = 0;
        public string Name { get; set; } = "nameless";    
        public event EventHandler<EventArgs> Barking;
    }

Any help would be appreciated, please.

svick
  • 236,525
  • 50
  • 385
  • 514
myfunnyfella
  • 1,357
  • 3
  • 18
  • 25
  • 1
    What error do you get? – rageit Jun 26 '15 at 18:29
  • 3
    Yes, event initializers were removed. The current feature status can be seen here: https://github.com/dotnet/roslyn/wiki/Languages-features-in-C%23-6-and-VB-14 – Dennis_E Jun 26 '15 at 18:30
  • There is a ugly workaround for this: see [this question](http://stackoverflow.com/questions/4751837/initializing-events-with-initializer-syntax) – ventiseis Jul 24 '16 at 20:05

0 Answers0