Home > Software engineering >  Is it Ok to use C# 8.0 with .Net 3.5
Is it Ok to use C# 8.0 with .Net 3.5

Time:12-12

Im creating Winform app that targets .NET 3.5. I have enabled C# 8.0 in the project file.

The main reason i used c# 8.0 is to use delegate void OnSomeEvent(object obj, string name); which i cant use in c# 7.3

enter image description here

enter image description here

The Interface is used by classes that are unknown at runtime. I want to use the interface to search and cast those classes usinf reflection then subscribe to the event they inherited.

So is it ok to use C# 8.0 with .NET 3.5?

CodePudding user response:

Certain features in newer versions of the C# language require the presence of specific classes at runtime. when you use these features, your application will not compile or fail during linking or at runtime.

An example is tuples that require the presence of the ValueTuple<> class.


With regard to the specific question: According to The history of C#

Default interface members require enhancements in the CLR.

So, you won't be able to use default interface methods with the 3.5 version of .net Framework.

However, in your example you just have a delegate declaration. You don't need to put the delegate declaration inside the interface. You can just put it before or after the interface declaration since delegates can be declared inside a namespace directly.

The event itself can be declared inside the interface, even in earlier versions of C#.

delegate void OnSomeEvent(object obj, string name);

public interface IUpdate
{
    event OnSomeEvent SomeEvent;
}
  • Related