Click here to Skip to main content
15,891,657 members
Home / Discussions / C#
   

C#

 
AnswerRe: About Reflecting and generics Pin
BobJanova14-Feb-12 23:20
BobJanova14-Feb-12 23:20 
GeneralRe: About Reflecting and generics Pin
PozzaVecia14-Feb-12 23:29
PozzaVecia14-Feb-12 23:29 
GeneralRe: About Reflecting and generics Pin
BobJanova15-Feb-12 0:50
BobJanova15-Feb-12 0:50 
GeneralRe: About Reflecting and generics Pin
PozzaVecia15-Feb-12 1:24
PozzaVecia15-Feb-12 1:24 
GeneralRe: About Reflecting and generics Pin
BobJanova15-Feb-12 1:59
BobJanova15-Feb-12 1:59 
GeneralRe: About Reflecting and generics Pin
PozzaVecia15-Feb-12 2:30
PozzaVecia15-Feb-12 2:30 
GeneralRe: About Reflecting and generics Pin
BobJanova15-Feb-12 2:37
BobJanova15-Feb-12 2:37 
GeneralRe: About Reflecting and generics Pin
GParkings15-Feb-12 2:52
GParkings15-Feb-12 2:52 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace TestGeneric
{
    class Program
    {
        static void Main(string[] args)
        {            
            string myCar = "carA";
            string myMoto = "motoB";
 
            mPricer Pr = new  mPricer(myCar,myMoto);
           
        }
    }
 
    public class mPricer 
    {
        double total;
        public mPricer(string carId, string motoId)
        {
            Car c = (car) Activator.CreateInstance(myCar);
            Moto m = (moto) Activator.CreateInstance(myMoto);
            total = c.GetPrice() + m.GetCost();        
        }
 
        public void ShowTotal() 
        {
            Console.WriteLine(total);
        }
    }
 
    public abstract class car { abstract public double GetPrice();}
    public class carA : car { public override double GetPrice() { return 11; } }
    public class carB : car { public override double GetPrice() { return 12; } }
 
    public abstract class moto { abstract public double GetCost(); }
    public class motoA : moto { public override double GetCost() { return 7; } }
    public class motoB : moto { public override double GetCost() { return 6; } }
 

}


That, i think, should do it ... you don't need a generic class
Pedis ex oris
Quidquid latine dictum sit, altum sonatur

GeneralRe: About Reflecting and generics Pin
GParkings15-Feb-12 2:54
GParkings15-Feb-12 2:54 
GeneralRe: About Reflecting and generics Pin
PozzaVecia15-Feb-12 3:09
PozzaVecia15-Feb-12 3:09 
GeneralRe: About Reflecting and generics Pin
GParkings15-Feb-12 3:25
GParkings15-Feb-12 3:25 
GeneralRe: About Reflecting and generics Pin
BobJanova15-Feb-12 3:40
BobJanova15-Feb-12 3:40 
GeneralRe: About Reflecting and generics Pin
PozzaVecia15-Feb-12 10:17
PozzaVecia15-Feb-12 10:17 
GeneralRe: About Reflecting and generics Pin
BobJanova15-Feb-12 21:57
BobJanova15-Feb-12 21:57 
GeneralRe: About Reflecting and generics Pin
PozzaVecia16-Feb-12 0:02
PozzaVecia16-Feb-12 0:02 
GeneralRe: About Reflecting and generics Pin
GParkings15-Feb-12 22:54
GParkings15-Feb-12 22:54 
GeneralRe: About Reflecting and generics Pin
PozzaVecia16-Feb-12 0:05
PozzaVecia16-Feb-12 0:05 
QuestionTeam Project Pin
tryharder14-Feb-12 10:23
tryharder14-Feb-12 10:23 
QuestionResponse.TransmitFile not working on local network Pin
Member 342693614-Feb-12 5:08
Member 342693614-Feb-12 5:08 
QuestionC# 2010 - Sql SMO Backup ? Pin
Paramu197314-Feb-12 4:20
Paramu197314-Feb-12 4:20 
AnswerRe: C# 2010 - Sql SMO Backup ? Pin
Eddy Vluggen14-Feb-12 7:26
professionalEddy Vluggen14-Feb-12 7:26 
GeneralRe: C# 2010 - Sql SMO Backup ? Pin
Paramu197314-Feb-12 18:45
Paramu197314-Feb-12 18:45 
GeneralRe: C# 2010 - Sql SMO Backup ? Pin
Paramu197314-Feb-12 22:32
Paramu197314-Feb-12 22:32 
QuestionInfoPath 2010 with C# code entered data disappearing Pin
Member 864367514-Feb-12 4:15
Member 864367514-Feb-12 4:15 
Questionhow can i create textBox in C# with email autocomplate exactly like "outlook To field" Pin
A7mad_14-Feb-12 1:41
A7mad_14-Feb-12 1:41 

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.