C
C#UnemployedNinja

Check value type of extended class instance

I have BaseClass and MyClass : BaseClass. Using val is BaseClass will return true for any object that is, or extends BaseClass. How can I check if the object is of type MyClass, and not BaseClass?
A
Angius41d ago
val is MyClass...?
U
UnemployedNinja41d ago
No description
U
UnemployedNinja41d ago
I want to make test2 return false
A
Angius41d ago
test2 is not BaseClass then
U
UnemployedNinja41d ago
Am I actually this dumb I think maybe I'm just overthinking it lol
P
Pobiega41d ago
Any instance of a subtype is also an instance of the base class, that's not changeable and is just how inheritance works So it's a bit unclear what you mean with "I want test2 to be false" - all MyClass instances are valid BaseClass instances
A
Aaron41d ago
test2.GetType() == typeof(BaseClass) I'm not sure why you want that, but that's how you do it
U
UnemployedNinja41d ago
I got it now. I was partially overthinking it, but I also didn't properly understand what I was trying to do. I got it now though :) Just using is/is not
Want results from more Discord servers?
Add your server
More Posts
✅ Am I using NumberFormatInfo properly?I have a list of ca. 400 numbers which I want to convert to percentage strings as part of an endpoin✅ .NET MAUI LayoutI am trying to create a password field with the show icon to the right of the password field, when iGetting an error for an undefined variableHello, I'm a CS major working on a project so I'm still pretty new. I'm getting a CS0165 error on liEnemy following after the player (MONOGAME)Im making a simple game using Monogame in visual studio. I have two sprites drawn on the screen (pinIm having an issue checking for collisions when comparing DateTime objects.I have this function that's supposed to check for collisions with bookings. I am using TimeSpans andclamping how fast a input (as a float) can change.Let’s say my Input X float changes in a amount of time from -1 to 1 (-1, -0.5, 0, 0.5, 1) so as an eIValueResolver won't work with AutoMapperHi guys , hope all of you doing well, I'm recently working on a project where I need to convert a spHelp with concurrency blocking issueI have a small app that runs CPU bound on multiple threads (amount of processors) On one PC it workFrontend not workingI dont really keen on frontend but I think have some knowledge about it would be nice, I'm learning JsonSerializerOptionsTo be continuedC# Dictionary questionHi, if i have a dictionary in C# defined like so: `Dictionary<string, List<int>> test;` and I do `Li✅ Avalonia not showing rows in datagridThere are no rows in my datagrid in Avalonia, the headers are visible. I've checked if my list is emInfinite loop```c# /// ------------------------------------------------------------ /// <summary> /// Creates a sHow to connect my c# backend with the frontend?Hello, I created a ASP NET Core Web Api project with the command dotnet new webapi -minimal. In my ✅ Using `Func<ReadOnlySpan<char>,bool>` but not allowed due to Pointer TypeI am building a parser, and performance is of concern. So instead of allocating infinite strings wheconcurrency and atomicity Asp.net core web api and efcorelet's say there's an endpoint called AssingUser() ,this endpoint assigns one donation to this currenBuilding a generic repository for mongodbhello folks I was thinking build a generic repository structure for mongodb. but someday if i want Reading large xml file from archive by using XmlReader in Parallel modeHello 👋. I am looking for how can I read data from archive xml file in Parallel mode. I have archiResizing the Console window - Console ApplicationHi there, I'm trying to resize the console window in a Console Application. I have tried multiple ✅ Creating a datetime with a timezoneHow do I create a `DateTime` with `new DateTime(2010, 05, 12);` and give it a specific `TimeZoneInfo