Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
1 vote
1 answer
98 views

Creating child classes that only inherit parents data once

Currently I'm trying to create some attribute let's call it "DoNotShareWithGrandChildren" that will be used by the highest level parent class but not the children classes below it. The issue ...
Caleb Laws's user avatar
-1 votes
4 answers
90 views

Accessing the variables of an object using the object type in C#

assuming I have a base class called AnimalTypes and 3 derived classes, all 4 containing only variables. What I want to do is to create a List or an Observable collection in which I can add any type of ...
nb-1999's user avatar
  • 29
-1 votes
1 answer
60 views

Is there a way to pull specific child class from a parent class object variable?

I have a Room class which holds a Mob object. A Mob object can either be of type Passive or of type Hostile and each have their own specific behavior. These Mob objects will move around from Room to ...
CreativeGuy888's user avatar
0 votes
2 answers
57 views

Converting objects to Subclass

I want to make a class Vehicle and two classes (PassengerVehicle and FreightVehicle) that inherit it. The problem is that when the user enters the type of vehicle he wants and when I convert an object ...
Kovelj789's user avatar
0 votes
2 answers
214 views

How to map JSON to objects and return a list of sub-classes objects?

Let's say I wish to create a diary to keep track an infant's daily activities. I have a parent class called DiaryEntries (fields: DateTime, PerformBy) Then I have 2 sub-class called: FeedingEntries (...
stand's user avatar
  • 1
-2 votes
1 answer
107 views

Check if an object is a type or a subtype [duplicate]

Consider the following code which checks if an object is of a specific type: public MyMethod(object myObject) { if (myObject.GetType() != typeof(MyClass)) { throw new ArgumentException(...
Al2110's user avatar
  • 576
0 votes
2 answers
42 views

Accessing a function of a class from a function of another class

I am trying to access the Update function of Key from the Update function of MainChar. Both classes inherit from the Sprite class. In Main Char I am getting the error: An object reference is required ...
callum_y's user avatar
0 votes
2 answers
56 views

How to display base and derived class properties on the same level in QuickWatch

I have defined the follow base and derived classes with their respective interfaces as per: public class SomeModule : ModBase, ISomeModule { public Parameter2<int> Param3 { get; set; } = ...
toughQuestions's user avatar
0 votes
2 answers
67 views

C# - Determine which class an object should use on instantiation?

I have 2 classes: Entity and Control. Entity: public class Entity { public float Rotate {get; private set;} readonly Control m_Control public Entity(float rot) { Rotate = rot; ...
zineryt's user avatar
  • 43
0 votes
1 answer
174 views

Inheritance between related classes [closed]

I need to tidy up a system that creates a bunch of Programs. Each Program is defined in the following way: A program contains multiple modules A module contains multiple parameters The C# looks ...
stackMeUp's user avatar
  • 542
0 votes
1 answer
1k views

How to force to implement all fields a C# object?

I have this object on a class library (project "A" that I want to use in my multiple projects ("B" and "C"): public class Notification : INotification { public string Id { get; set; } public ...
Kiril1512's user avatar
  • 3,493
-4 votes
1 answer
176 views

Multiple Inheritance Substitute in C# - Specific Hypothetical Example With Logic in The Properties

Let’s say there are 2 classes that have the same prop, with logic in that prop as well. public class Manager { private string _ssn { get; set; } [RegularExpression(@"\d{9}")] public ...
Tyler Youngs's user avatar
0 votes
1 answer
133 views

Returning a nested class from inherited class

New to c# and trying to follow a specific code structure in building a weather API public class weatherData { public class coordinates { protected string longitude; //coord.lon ...
Vinayak's user avatar
-5 votes
1 answer
793 views

Why I am not able to call methods of child class from parent's reference variable [duplicate]

Here I am able to call parent class method from the instance of child class and reference variable of parent class. public class A { public void showA() { Console.WriteLine("showA"); ...
Naqi's user avatar
  • 144
2 votes
3 answers
54 views

Why doesn't a reference variable of type A which contains reference to an object of type B can't access member functions of class B?

Why can't objA access methodB() since it contains the reference to an object of class B type? Class A { public void methodA() { ......... } } Class B:A { public void ...
user avatar

15 30 50 per page