Click here to Skip to main content
15,867,934 members
Home / Discussions / C#
   

C#

 
GeneralRe: Is there any technique available for copying one object of class A to another object of class B ? Pin
PIEBALDconsult7-Aug-10 4:21
mvePIEBALDconsult7-Aug-10 4:21 
GeneralRe: Is there any technique available for copying one object of class A to another object of class B ? Pin
il_manti3-Nov-10 23:36
il_manti3-Nov-10 23:36 
AnswerRe: Is there any technique available for copying one object of class A to another object of class B ? Pin
Łukasz Nowakowski5-Aug-10 21:41
Łukasz Nowakowski5-Aug-10 21:41 
QuestionBest Way to Go About Updating Forms When A Piece of Data Is Changed Pin
Matt U.5-Aug-10 11:44
Matt U.5-Aug-10 11:44 
AnswerRe: Best Way to Go About Updating Forms When A Piece of Data Is Changed Pin
Chris Trelawny-Ross9-Aug-10 8:23
Chris Trelawny-Ross9-Aug-10 8:23 
QuestionInterface Events Pin
Ian Grech5-Aug-10 10:52
Ian Grech5-Aug-10 10:52 
AnswerRe: Interface Events Pin
PIEBALDconsult5-Aug-10 16:56
mvePIEBALDconsult5-Aug-10 16:56 
AnswerRe: Interface Events Pin
Chris Trelawny-Ross9-Aug-10 8:53
Chris Trelawny-Ross9-Aug-10 8:53 
So what you're wanting is to expose the event at the type level, not the instance level.

Since interfaces do not allow static members, you'll have to create an abstract base class:
    public delegate void CountReachedDelegate(CountableBase countableBase, string message);

 
    public abstract class CountableBase
        {
        public static event CountReachedDelegate CountReached;
 
        public static void OnCountReached(CountableBase item, string message)
            {
            CountReachedDelegate del = CountReached;    // Use local variable for thread safety
            if (del != null)
                del(item, message);
            }
 
        public abstract void Count(int limit);
        }

 
    public class SubIntA : CountableBase
        {
        private int _T = 20;
        public int Trigger
            { get { return _T; } }
         
        string _N = "A";
        public string Name
            { get { return _N; } }
 
        public override void Count(int limit)
            {
            for (int x = 0; x < limit; x++)
                if (x % _T == 0)
                    OnCountReached(this, _N + "=" + x);
            }
        }

 
    public class SubIntB : SubIntA { }


Note that I've implemented SubIntA and SubIntB one in terms of the other. Of course, your app will be different in that regard. Depending on the degree of similarity between these classes, I'd recommend moving any count-related behavior, especially if it relates to the threshold, into the abstract base class. The aim here is to keep all related behavior in the same class (and, ideally, all behavior in a class is related to all other behavior in the class and all unrelated behavior is in another class).

BTW: your threshold check condition (x % _T == 0) will fire on x == 0 and on the threshold. Probably not what you want. D'Oh! | :doh:
GeneralRe: Interface Events Pin
Ian Grech13-Aug-10 0:34
Ian Grech13-Aug-10 0:34 
QuestionEfficient way to create a bitmap from a stream of bits in a file Pin
Adam Covitch5-Aug-10 10:50
Adam Covitch5-Aug-10 10:50 
AnswerRe: Efficient way to create a bitmap from a stream of bits in a file Pin
Eddy Vluggen5-Aug-10 11:31
professionalEddy Vluggen5-Aug-10 11:31 
AnswerRe: Efficient way to create a bitmap from a stream of bits in a file Pin
harold aptroot5-Aug-10 11:43
harold aptroot5-Aug-10 11:43 
AnswerRe: Efficient way to create a bitmap from a stream of bits in a file [modified] Pin
Luc Pattyn5-Aug-10 12:03
sitebuilderLuc Pattyn5-Aug-10 12:03 
GeneralRe: Efficient way to create a bitmap from a stream of bits in a file Pin
Adam Covitch9-Aug-10 7:02
Adam Covitch9-Aug-10 7:02 
GeneralRe: Efficient way to create a bitmap from a stream of bits in a file Pin
Luc Pattyn9-Aug-10 7:28
sitebuilderLuc Pattyn9-Aug-10 7:28 
GeneralRe: Efficient way to create a bitmap from a stream of bits in a file Pin
Adam Covitch9-Aug-10 7:34
Adam Covitch9-Aug-10 7:34 
GeneralRe: Efficient way to create a bitmap from a stream of bits in a file Pin
Luc Pattyn9-Aug-10 7:48
sitebuilderLuc Pattyn9-Aug-10 7:48 
Questionclass function Pin
v_neil875-Aug-10 10:46
v_neil875-Aug-10 10:46 
AnswerRe: class function Pin
Pete O'Hanlon5-Aug-10 12:16
subeditorPete O'Hanlon5-Aug-10 12:16 
QuestionInvoking C code from C# Pin
tamash_ionut5-Aug-10 9:59
tamash_ionut5-Aug-10 9:59 
AnswerRe: Invoking C code from C# Pin
DaveyM695-Aug-10 10:06
professionalDaveyM695-Aug-10 10:06 
AnswerRe: Invoking C code from C# Pin
Luc Pattyn5-Aug-10 12:15
sitebuilderLuc Pattyn5-Aug-10 12:15 
QuestionProgram installer to require a specific Windows OS? Pin
uhcafigdc5-Aug-10 6:15
uhcafigdc5-Aug-10 6:15 
AnswerRe: Program installer to require a specific Windows OS? Pin
Not Active5-Aug-10 6:32
mentorNot Active5-Aug-10 6:32 
GeneralRe: Program installer to require a specific Windows OS? Pin
uhcafigdc5-Aug-10 7:11
uhcafigdc5-Aug-10 7:11 

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.