小编Myr*_*rez的帖子

哪个是使用委托的正确方法?

我想两个人知道两者之间是否存在差异,如果它们是相同的哪个是更好的做法?

第一类:

Action onDeath;
public void RegisterDeath(Action callback) 
{
    onDeath += callback;
}
Run Code Online (Sandbox Code Playgroud)

然后让其他类2订阅这个RegisterDeath方法?或者做得更好:

public Action onDeath;
//or even
public event Action onDeath;
Run Code Online (Sandbox Code Playgroud)

并且在主类中没有杂乱地订阅这个公共委托?如果存在差异,可能会有人简要解释一下

c#

2
推荐指数
1
解决办法
56
查看次数

如何将十六进制转换为int

首先,我收到数据并将其转换为字符串.

data = client.Receive(ref ep);
string received = BitConverter.ToString(data);
Run Code Online (Sandbox Code Playgroud)

我得到的字符串是FF-FF-FF-FF-66-0A.我尝试从中获取INT值.

foreach (var item in received)
{
    int rec = Convert.ToInt32(item);
    int rec = Convert.ToInt32(item,16); 

    //IF I try second line I get error
    //cannot convert from 'int' to 'system.iformatprovider' 
}
Run Code Online (Sandbox Code Playgroud)

从使用第一行int rec = Convert.ToInt32(item); 我得到的数字是70 70 70 70 45 45 70 70 70 70

正如我想的那样,我正在转换F> 70和F> 70,但是如何通过获得FF> 255来转换FF并使其工作

c#

1
推荐指数
1
解决办法
1633
查看次数

不能减去球员的HP

我试图减去球员的HP.

这是我的代码示例:

class player():
    def __init__(self):
        self.hp = 100

    def check_death(self):
    ....

p = player()
p.hp - 10
print p.hp
Run Code Online (Sandbox Code Playgroud)

但它是打印100所以没有减法完成如何解决它?谢谢!

python

0
推荐指数
1
解决办法
61
查看次数

标签 统计

c# ×2

python ×1