我想两个人知道两者之间是否存在差异,如果它们是相同的哪个是更好的做法?
第一类:
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)
并且在主类中没有杂乱地订阅这个公共委托?如果存在差异,可能会有人简要解释一下
首先,我收到数据并将其转换为字符串.
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并使其工作
我试图减去球员的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所以没有减法完成如何解决它?谢谢!