委托变量不会在intellisense中显示 [英] Delegate variable dosen't show in intellisense
本文介绍了委托变量不会在intellisense中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个控制台应用程序,我有一个名为class1.cs的类,我正在尝试在其中实现
委托,如代码所示。
I have a console application in that i have one class named class1.cs and i am trying to implement
delegates in it as shown in the code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace testingconsoleapplication
{
delegate int adding(int a, int b);
class test
{
public adding sum = add;
private static int add(int i, int j)
{
return i + j;
}
private static int sub(int i, int j)
{
return i - j;
}
}
}
这是我的program.cs文件
while this is my program.cs file
namespace testingconsoleapplication
{
class Program
{
static void Main(string[] args)
{
int i = 2, j=1;
test a = new test();
Console.WriteLine(a.sum.Invoke(i,j));
Console.ReadLine();
}
}
}
现在,它只适用于一种方法,当我尝试添加另一个方法来委托变量首先它不会在intellisense中显示sum变量,其次它允许添加第二个方法。如何添加第二个方法?
Now,it's working fine for only one method and when i try to add another method to delegate variable firstly it dosen't show the "sum" variable in intellisense and secondly it dosent allow to add second method.How can i add second method ?
推荐答案
你确定吗?它适用于我,(虽然你不需要调用调用)
Are you sure? It works fine for me, (although you don't need the Invoke call)
int i = 2, j = 1;
test a = new test();
Console.WriteLine(a.sum.Invoke(i, j));
Console.WriteLine(a.nsum.Invoke(i, j));
Console.WriteLine(a.sum(i, j));
Console.WriteLine(a.nsum(j, i));
...
delegate int adding(int a, int b);
class test
{
public adding sum = add;
public adding nsum = sub;
private static int add(int i, int j)
{
return i + j;
}
private static int sub(int i, int j)
{
return i - j;
}
}
Intellisense向我显示总和
和 nsum
委托......
Intellisense shows me both the sum
and nsum
delegates...
这篇关于委托变量不会在intellisense中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文