C# Method Resolution, long vs int

The int version of bar is being called, because 10 is an int literal and the compiler will look for the method which closest matches the input variable(s). To call the long version, you’ll need to specify a long literal like so: foo.bar(10L); Here is a post by Eric Lippert on much more complicated versions …

Read more

How to get list of controllers and actions in ruby on rails?

The easiest way to get a list of controller classes is: ApplicationController.descendants However, as classes are loaded lazily, you will need to eager load all your classes before you do this. Keep in mind that this method will take time, and it will slow down your boot: Rails.application.eager_load! To get all the actions in a …

Read more

How do methods use hash arguments in Ruby?

Example: def foo(regular, hash={}) puts “regular: #{regular}” puts “hash: #{hash}” puts “a: #{hash[:a]}” puts “b: #{hash[:b]}” end foo(“regular argument”, a: 12, :b => 13) I use hash={} to specify that the last argument is a hash, with default value of empty hash. Now, when I write: foo(“regular argument”, a: 12, :b => 13) It’s actually …

Read more

Calling a Activity method from BroadcastReceiver in Android

try this code : your broadcastreceiver class for internet lost class : public class InternetLostReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { context.sendBroadcast(new Intent(“INTERNET_LOST”)); } } in your activity add this for calling broadcast: public class TestActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); registerReceiver(broadcastReceiver, new IntentFilter(“INTERNET_LOST”)); } BroadcastReceiver …

Read more