【问题标题】:What does '~' mean when debug in C#?在 C# 中调试时,'~' 是什么意思?
【发布时间】:2013-04-01 23:58:58
【问题描述】:

这是我的方法:

public static void send(byte[] packet)
{
    Console.Write(DateTime.Now.ToString() + ": ");
    foreach (byte b in packet)
    {
        Console.Write(b.ToString("X2") + " ");
    }
    Console.WriteLine();
    if (connected)
    {
        try
        {
            connection.Socket.Send(packet);        
        }
        catch (Exception)
        {
            throw new Exception("Can't send packet");
        }
    }        
}

来电者

public void addPacket(PacketProcessed packet) 
{
    int messageEvent = (int)Event.Type.Normal;
    int speed = 0;
    foreach (MessageProcessed message in packet.messages)
    {
        if ((currentlyEvent & (int)Event.Type.Speed) == (int)Event.Type.Speed)
        {
            if (Math.Abs(message.xSpeed) >= this.speedLimit - this.speedLimit * 0.1)
            {
                messageEvent |= (int)Event.Type.Speed;
                speed = Math.Max(speed, (int)Math.Abs(message.xSpeed));
            }
        }
        else
        {
            if (Math.Abs(message.xSpeed) >= this.speedLimit)
            {
                messageEvent |= (int)Event.Type.Speed;
                speed = Math.Max(speed, (int)Math.Abs(message.xSpeed));
            }
        }
    }
    this.currentlyEvent = messageEvent;
    if (this.currentlyEvent != historyEvent)
    {
        byte[] bb = ProtocolBuilder.buildProtocal(0xE0 + location, currentlyEvent, (byte)speed);
        TCPTalker.send(bb);    // <--- This line call above (send) method.
    }
    historyEvent = currentlyEvent;
    packetStorage.Add(packet);
}

输出看起来像

~4/10/2013 3:10:59 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 44 E6 02 42 
~4/10/2013 3:11:00 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 00 E6 00 88 
4/10/2013 3:11:00 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 45 E6 02 41 
~~4/10/2013 3:11:04 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 00 E6 00 88 
~4/10/2013 3:11:05 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 3C E3 02 4D 
~4/10/2013 3:11:13 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 00 E2 00 8C 
4/10/2013 3:11:13 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 41 E2 02 49 
~~4/10/2013 3:11:18 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 00 E3 00 8B 
~4/10/2013 3:11:19 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 40 E6 02 46 
~4/10/2013 3:11:24 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 3D E3 02 4C 
~4/10/2013 3:11:25 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 00 E6 00 88 
4/10/2013 3:11:25 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 00 E3 00 8B 
~~4/10/2013 3:11:26 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 3D E3 02 4C 
~4/10/2013 3:11:30 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 00 E2 00 8C 
~4/10/2013 3:11:38 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 42 E6 02 44 
~4/10/2013 3:11:44 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 00 E3 00 8B 
~4/10/2013 3:11:47 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 3C E2 02 4E 
~4/10/2013 3:11:50 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 00 E6 00 88 
~4/10/2013 3:11:56 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 00 E2 00 8C 
4/10/2013 3:11:56 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 3D E2 02 4D 
~~4/10/2013 3:11:57 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 00 E2 00 8C 
~4/10/2013 3:11:59 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 3C E2 02 4E 
~4/10/2013 3:12:01 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 00 E2 00 8C 
~4/10/2013 3:12:05 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 46 E2 02 44 
~4/10/2013 3:12:12 PM: 7E 00 1A 10 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 46 3A 00 00 00 00 00 E2 00 8C 
~

我看到“~”出现在我的调试字符串出现之前。 有时输出窗口显示 ~ 然后 ~ 然后我的调试字符串看起来像 ~~4/10/2013 3:12:01 PM: 7E 00 ...

“~”是什么意思?

【问题讨论】:

  • 你确定不是自己在程序的其他地方编写的吗?
  • 您能否在一个绝对不包含任何其他对 Console.WriteLine 调用的简短但完整的程序中重现此内容?
  • @Jon Console.Write 而不是 Console.WriteLine,可能 - 因为它不是行终止的
  • @MarcGravell:非常正确。
  • 感谢 nvoigt!我已经检查过了。但是什么也没找到。

标签: c# debugging tilde


【解决方案1】:

它没有任何预定义的含义。我会检查您的其他代码以获取对Console.Write 的调用; 完全猜测,也许检查任何终结器 - 也许他们有一些输出,例如:

class Foo {
    ~Foo() {
        #if DEBUG
        // show that I got collected; hey I know - let's write to the console...
        // that won't confuse *anyone*
        Console.Write("~");
        #endif
    }
}

但是对~ 进行全局搜索 (ctrl+shift+f) 应该会找到它。

【讨论】:

  • 感谢 Marc Gravell!我已经做到了。但是什么也没找到。
  • @Pruk 和Console.Write?另外:您正在使用哪些其他库(如果有)?它有可能来自其中之一吗?事情是这样的:.NET 不会无缘无故地将~ 添加到标准输出。它来自选择性地执行此操作的应用程序(您的代码或 dll)中的某个位置。
  • 抱歉,我的项目没有其他库。我正在使用 VC# 2010 Express。希望这些信息对您有所帮助..
猜你喜欢
  • 2013-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-07
  • 2016-12-08
  • 2016-04-19
  • 2015-04-11
  • 2012-04-25
相关资源
最近更新 更多