1
    Dim objCar As Car
    objCar = New Car
    Console.WriteLine("{0}", objCar.GetType.ToString())

Returns this

Objects.Car

Can I change the code slightly, without using text functions, to just return the following?

Car

4

2 回答 2

3

Did you Try this.?

Dim objCar  As car
objCar  = New car
MsgBox(objCar.GetType.Name)
于 2013-03-30T12:38:48.163 回答
1

Why not just override the ToString method on your Car class?

public class Car
{
    public Car() {}

    public override string ToString()
    {
        return "Car";
    }
}

That way you can return whatever you want to return out of it without having to use GetType.

于 2013-03-30T12:16:37.773 回答