whytheq
whytheq

Reputation: 35567

Return just the object type name without preceding "Objects."

    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

Upvotes: 1

Views: 82

Answers (2)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Did you Try this.?

Dim objCar  As car
objCar  = New car
MsgBox(objCar.GetType.Name)

Upvotes: 3

antinescience
antinescience

Reputation: 2359

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.

Upvotes: 1

Related Questions