הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Object and collection initializer expressions may not be applied to a delegate creation expression.
A delegate has no members like a class or struct has, and so there is nothing for an object initializer to initialize. If you encounter this error, it is probably because there are braces after the delegate creation expression. Just remove the braces and this error will disappear.
- Remove the braces.
The following code produces CS1958:
// cs1958.cs
public class MemberInitializerTest
{
delegate void D<T>();
public static void GenericMethod<T>() { }
public static void Run()
{
D<int> genD = new D<int>(GenericMethod<int>) { }; // CS1958
// Try the following line instead
// D<int> genD = new D<int>(GenericMethod<int>);
}
}
משוב של .NET
.NET הוא פרויקט קוד פתוח. בחר קישור כדי לספק משוב: