Get the instance name of this

后端 未结 4 1738
攒了一身酷
攒了一身酷 2021-01-22 08:50

Is this possible!!?!?!?!?

I\'m trying to make a set of classes that model a number of different types of things. Properties of these things change over time, and I want

4条回答
  •  春和景丽
    2021-01-22 09:52

    I know, I know, old post.

    but I found a solution...

    public static List Packets = new List();
    public class Packet
    {
        public Packet()
        {
            Packets.Add(this);
        }
        public string packetName;
    }
    
    public Packet myPacket = new Packet();
    myPacket.packetName = "myPacket";
    
    public void SomeMethod()
    {
        int x = 0;
        foreach (Packet p in Packets)
        {
            if (p.packetName = "myPacket")
            {
                Packet myPacket = Packets[x];
                break;
            }
            x++;
        }
    }
    

提交回复
热议问题