Naming C# events and handlers properly -


from i've read i'm not sure if i've got naming convention events , handlers correct. (there seems conflicting advice out there).

in 2 classes below can tell me if i've got naming right event, method raises event , method handles event?

public class car {  // event named correctly?  public event eventhandler<eventargs> onsomethinghashappened;   private void moveforward()  {   raisesomethinghashappened();  }   // named correctly  private void raisesomethinghashappened()  {   if(onsomethinghashappened != null)   {    onsomethinghashappened(this, new eventargs());    }  } } 

and subscriber class:

public class subscriber() {  public subscriber()  {   car car = new car();   car.onsomethinghashappened += car_somethinghashappened();  }   // named correctly?  private void car_somethinghashappened(object sender, eventargs e)  {   // stuff  } } 

thanks in advance!

almost

the method fire event - on<when>event (from raisesomethinghashappened)

i.e. onbeforeopen, onclosing, onsomethighashappened

the event <when>event (from onsomethinghashappened)

i.e. beforeopen, closing, somethinghashappened

the handler <the instance or meaningful name><_><event> (from car_somethinghashappened)

i.e. form_beforeopen, window_closing, car_somethinghashappened -> perfect


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -