All Questions
60
questions
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 ...
-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 ...
-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 ...
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 ...
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 (...
-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(...
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 ...
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; } = ...
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;
...
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 ...
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 ...
-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 ...
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 ...
-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");
...
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 ...