- Where Developers Learn, Share, & Build Careers
I have an ideal in which I have an abstract class (it's called vehicle
) and Classes in the form of many heritage bikes
, motorbike
, car
, van
etc., it is basically a real Simplified version is world problem
Abstract class auto id; Int wheelcount; String OwnerName; Class Bike Datetime Latest Security Checks; Class motorbike-engine engine class car double engines class van double storage capacitance
I have a system that is IEnumerable & lt; Vehicle & gt;
in which each of these threads is contained in Secure Singleton Class, which essentially acts as an in-memory database.
I want to make a method in my application (in singleton or separate class) which allows me to query only for a certain type of vehicle.
Initially I thought of a method:
Internal IEnumerable & lt; T & gt; GetVehicles & lt; T & gt; () Where T: Vehicle
In order to be able to provide a type T
, which would like to retrieve that type. I know that I can use type () to do logic, but I do not know how to return my values? I am struggling with the basics of the method, and I think there should be a design pattern which means a lot more.
LINQ already has this method -:
var vans = vehicle. Optty Type & lt; Wan & gt; ();
To determine that an example is an example of a type that you do not need to use typeof ()
, you and operators use (And they can also be used with normal type):
if (vehicle is vane) ... if (vehicle is t) ...
or
variant = vehicle in the form of van; If (van! = Null) ... var example = vehicle in t; // will require t: class generic type barrier if (example! = Faucet) ... var instance = vehicle as t ?; // will be required: if the structure is the type of generic type (example! = Tap) ...
Comments
Post a Comment