Click here to Skip to main content
15,888,610 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# - run exe from within a form, and keep the exe's borders within the actual boundary of the form... Pin
Afzaal Ahmad Zeeshan21-Oct-17 1:53
professionalAfzaal Ahmad Zeeshan21-Oct-17 1:53 
AnswerRe: C# - run exe from within a form, and keep the exe's borders within the actual boundary of the form... Pin
lmoelleb12-Oct-17 19:28
lmoelleb12-Oct-17 19:28 
QuestionC# Listview Pin
danmor49812-Oct-17 9:52
danmor49812-Oct-17 9:52 
AnswerRe: C# Listview Pin
Afzaal Ahmad Zeeshan12-Oct-17 16:33
professionalAfzaal Ahmad Zeeshan12-Oct-17 16:33 
GeneralRe: C# Listview Pin
danmor49816-Oct-17 4:56
danmor49816-Oct-17 4:56 
GeneralRe: C# Listview Pin
Simon_Whale17-Oct-17 4:45
Simon_Whale17-Oct-17 4:45 
GeneralRe: C# Listview Pin
danmor49818-Oct-17 6:18
danmor49818-Oct-17 6:18 
QuestionInheriting generic classes from base classes with generic parameters. Error converting to base type. Pin
mbv80011-Oct-17 11:48
mbv80011-Oct-17 11:48 
I am trying to get the code below to work, but I can't figure it out. Can someone guide me to solve this issue? The code is ready to be copied to a console application.

C#
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Vehicle<Actions> aCar = new Car();  // Error: Cannot Implicitly convert type Car
                                                // to Vehicle<Actions>

            Vehicle<Actions> anAirplane = new Airplane(); // Error: Cannot Implicitly convert type
                                                          // Airplane to Vehicle<Actions>

            List<Vehicle<Actions>> list = new List<Vehicle<Actions>>()
            {
                aCar,
                anAirplane
            };
            
            foreach (var vehicle in list)
            {
                vehicle.actions.ID = "any";
                vehicle.actions.PerformAction();
            }
            Console.WriteLine("Good");
        }
    }


    public interface IVehicle<TActions> where TActions : IActions
    {
        TActions actions { get; set; }
    }
    public class Vehicle<TActions> : IVehicle<TActions> where TActions : Actions
    {
        TActions _actions;
        public TActions actions { get => _actions; set => _actions = value; }
    }
    public class Car : Vehicle<CarActions> 
    {
        public int Wheels { get; set; }
    }

    public class Airplane : Vehicle<AirplaneActions> {}

    public interface IActions
    {
        string ID { get; set; }
        void PerformAction();
    }

    public abstract class Actions : IActions
    {
        public string ID { get ; set; }
        public abstract void PerformAction();
    }


    public class CarActions : Actions
    {
        int speed;
        public override void PerformAction()
        {
            speed = 50;
        }
    }

    public class AirplaneActions : Actions
    {
        int Height;
        public override void PerformAction()
        {
            Height = 5000;
        }
    }
}


modified 11-Oct-17 18:50pm.

QuestionRe: Inheriting generic classes from base classes with generic parameters. Error converting to base type. Pin
Eddy Vluggen11-Oct-17 12:53
professionalEddy Vluggen11-Oct-17 12:53 
GeneralRe: Inheriting generic classes from base classes with generic parameters. Error converting to base type. Pin
PIEBALDconsult11-Oct-17 13:17
mvePIEBALDconsult11-Oct-17 13:17 
GeneralRe: Inheriting generic classes from base classes with generic parameters. Error converting to base type. Pin
Eddy Vluggen11-Oct-17 13:43
professionalEddy Vluggen11-Oct-17 13:43 
AnswerRe: Inheriting generic classes from base classes with generic parameters. Error converting to base type. Pin
mbv80012-Oct-17 1:50
mbv80012-Oct-17 1:50 
GeneralRe: Inheriting generic classes from base classes with generic parameters. Error converting to base type. Pin
PIEBALDconsult11-Oct-17 13:30
mvePIEBALDconsult11-Oct-17 13:30 
GeneralRe: Inheriting generic classes from base classes with generic parameters. Error converting to base type. Pin
mbv80012-Oct-17 5:44
mbv80012-Oct-17 5:44 
AnswerRe: Inheriting generic classes from base classes with generic parameters. Error converting to base type. Pin
Richard Deeming12-Oct-17 3:50
mveRichard Deeming12-Oct-17 3:50 
GeneralRe: Inheriting generic classes from base classes with generic parameters. Error converting to base type. Pin
mbv80012-Oct-17 5:42
mbv80012-Oct-17 5:42 
GeneralRe: Inheriting generic classes from base classes with generic parameters. Error converting to base type. Pin
PIEBALDconsult12-Oct-17 12:44
mvePIEBALDconsult12-Oct-17 12:44 
QuestionMongoDB File upload Pin
Elias Zaman11-Oct-17 1:10
Elias Zaman11-Oct-17 1:10 
AnswerRe: MongoDB File upload Pin
OriginalGriff11-Oct-17 1:26
mveOriginalGriff11-Oct-17 1:26 
GeneralRe: MongoDB File upload Pin
Elias Zaman12-Oct-17 17:56
Elias Zaman12-Oct-17 17:56 
GeneralRe: MongoDB File upload Pin
OriginalGriff12-Oct-17 19:26
mveOriginalGriff12-Oct-17 19:26 
AnswerRe: MongoDB File upload Pin
Nathan Minier11-Oct-17 1:36
professionalNathan Minier11-Oct-17 1:36 
QuestionDictionary Pin
Member 114992589-Oct-17 11:04
Member 114992589-Oct-17 11:04 
AnswerRe: Dictionary Pin
Mycroft Holmes9-Oct-17 12:55
professionalMycroft Holmes9-Oct-17 12:55 
AnswerRe: Dictionary Pin
Pete O'Hanlon9-Oct-17 20:16
mvePete O'Hanlon9-Oct-17 20:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.