C# 如何将这段ruby代码转换为c?

C# 如何将这段ruby代码转换为c?,c#,ruby,C#,Ruby,我有一段Ruby代码: server_id = "0xf9f1e687" actions = "S(#{Time.now.to_f * 1000).to_i.to_s})S(12946;server:#{server_id.to_i(16).to_s})" 我怎么用C写呢 最接近我的是: int server_id = (int)new System.ComponentModel.Int32Converter() .ConvertFromString("0xf

我有一段Ruby代码:

server_id = "0xf9f1e687"

actions = "S(#{Time.now.to_f * 1000).to_i.to_s})S(12946;server:#{server_id.to_i(16).to_s})"
我怎么用C写呢

最接近我的是:

int server_id = (int)new System.ComponentModel.Int32Converter()
                .ConvertFromString("0xf9f1e687");

var actions = "S(" + DateTime.Now.Second + ")S(12946;server:" + server_id + ")";

因为您的问题只是将字符串转换为int-我将解决这个问题。编号0xf9f1e687超出C Int32的范围。Int32.MaxValue是0x7FFFFFFF。这就是为什么你的转换给出了错误的负值。如果它只是抛出一个异常会更好,但它不会。要修复此问题,请使用长Int64或无符号int UInt32:

替代方法:

var server_id = uint.Parse("0xf9f1e687".Replace("0x", ""), NumberStyles.AllowHexSpecifier);

所以你是用C写的。它是否按预期工作?不,从字符串到Int的转换失败。
var server_id = uint.Parse("0xf9f1e687".Replace("0x", ""), NumberStyles.AllowHexSpecifier);