My name is Edward Tanguay. I'm an American software and web developer living and working in Berlin, Germany.
C# CODE EXAMPLE created on Saturday, June 26, 2010 permalink
How to use a custom parameter struct to pass any number of variables to constructors of similar classes.
This shows a common pattern to pass in a collection of unlike typed variables into constructors of similar classes, the inherited class of which saves the common variables locally while each asy then unpacks each of its specific variables. Putting all variables in a custom struct like this enables you to avoid the runtime recasting of the variables that a Dictionary<string,object> solution would cause.
using System;
using System.Collections.Generic;
using System.Text;

namespace TestPass234
{
    class Program
    {
        static void Main(string[] args)
        {
            List<SectionItem> sectionItems = new List<SectionItem>();

            {
                SectionItemParameters vars = new SectionItemParameters();
                vars.SectionNumber = 1;
                vars.Title = "Lesson #1";
                vars.StartDate = new DateTime(2008, 12, 25);
                List<Flashcard> flascards = new List<Flashcard>();
                flascards.Add(new Flashcard { Question = "What color is the sky?", Answer = "blue" });
                flascards.Add(new Flashcard { Question = "What color is the sun?", Answer = "yellow" });
                vars.Flashcards = flascards;
                SectionItem sectionItem = SectionItem.Instantiate("lesson", vars);
                sectionItems.Add(sectionItem);
            }

            {
                SectionItemParameters vars = new SectionItemParameters();
                vars.Title = "Info #1";
                vars.Content = "This is info number one.";
                SectionItem sectionItem = SectionItem.Instantiate("info", vars);
                sectionItems.Add(sectionItem);
            }

            foreach (var sectionItem in sectionItems)
            {
                Console.WriteLine(sectionItem.Render());
            }
            Console.ReadLine();
        }
    }

    public class SectionItem
    {
        protected string _title;

        public SectionItem()
        { }

        public SectionItem(SectionItemParameters vars)
        {
            _title = vars.Title;
        }

        public static SectionItem Instantiate(string idCode, SectionItemParameters vars)
        {
            switch (idCode)
            {
                case "lesson":
                    return new SectionItemLesson(vars);
                case "info":
                    return new SectionItemInfo(vars);
                default:
                    return new SectionItem();
            }
        }

        public virtual string Render()
        {
            return "undefined section item";
        }

    }


    public class SectionItemLesson : SectionItem
    {
        private int _sectionNumber;
        private DateTime _startDate;
        private List<Flashcard> _flashcards = new List<Flashcard>();

        public SectionItemLesson(SectionItemParameters vars)
            : base(vars)
        {
            _sectionNumber = vars.SectionNumber;
            _startDate = vars.StartDate;
            _flashcards = vars.Flashcards;
        }

        public override string Render()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(String.Format(">>> {0}. {1} (Starts {2:ddd, MMM d, yyyy})", _sectionNumber, _title, _startDate));
            foreach (var flashcard in _flashcards)
                sb.AppendLine("    - " + flashcard.Render());
            return sb.ToString();
        }
    }

    public class SectionItemInfo : SectionItem
    {
        private string _content;

        public SectionItemInfo(SectionItemParameters vars)
            : base(vars)
        {
            _content = vars.Content;
        }

        public override string Render()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(String.Format(">>> {0}", _title));
            sb.AppendLine(String.Format("    {0}", _content));
            return sb.ToString();
        }
    }

    public class Flashcard
    {
        public string Question { get; set; }
        public string Answer { get; set; }

        public string Render()
        {
            return "Q: " + Question + " A: " + Answer;
        }
    }

    public struct SectionItemParameters
    {
        public string Title { get; set; }
        public int SectionNumber { get; set; }
        public DateTime StartDate { get; set; }
        public List<Flashcard> Flashcards { get; set; }
        public string Content { get; set; }
    }
}
need markup?