Determining type of an object in ruby

The proper way to determine the “type” of an object, which is a wobbly term in the Ruby world, is to call object.class. Since classes can inherit from other classes, if you want to determine if an object is “of a particular type” you might call object.is_a?(ClassName) to see if object is of type ClassName or derived from it. Normally type checking … Read more

Equivalent of console.log in C#

Trace.WriteLine will do (and probably more methods from the Trace class). You can use a program called DebugView to real-time monitor the trace generated, or write to a log file using you web.config file.

Categories c# Tags

How can I convert a char to CharSequence?

I give you an example: Syntax of String contains method Parameters String “e” − This is the sequence to search Return Value This method returns true only if this string contains “e” else false. Exception NullPointerException − if the value of the parameter is null. Example

What is the advantage of using try {} catch {} versus if {} else {}

I’d use the try/catch block when the normal path through the code should proceed without error unless there are truly some exceptional conditions — like the server being down, your credentials being expired or incorrect. I wouldn’t necessarily use it to handle non-exceptional errors — say like the current user not being in the correct … Read more

How does the SQL injection from the “Bobby Tables” XKCD comic work?

It drops the students table. The original code in the school’s program probably looks something like This is the naive way to add text input into a query, and is very bad, as you will see. After the values from the first name, middle name textbox FNMName.Text (which is Robert’); DROP TABLE STUDENTS; –) and the last name textbox LName.Text (let’s … Read more