Tuesday, April 29, 2008

Ruby on Rails: Difference between <% %> and <% -%>

<% -%> supress the trailing new line. You can also use <%- %> to supress leading whitespace. You need to use <%= %> when you need to output something.

Wednesday, April 23, 2008

Ruby on Rails: undefined method `render_text'

Change render_text "Hello World" to render :text => "Hello World"

Thursday, April 10, 2008

C# : How to convert a string to an enum?

Use Enum.Parse()

Eg:
enum eType
{
Type1,
Type2,
Type3
}

eType obj = (eType) Enum.Parse(typeof(eType), "Type1");

Wednesday, April 9, 2008

How to use variable number of parameters in C#

It is very easy to use variable number of parameters in C# with the help of params keyword.

Here is a small example which will find the largest integer in from a list of integers where the size of the list is unknown.

public int FindLargest(int Num, params int[] Nums)
{
int Large = Num;
foreach (int n in Nums)
{
if (n > Large)
{
Large = n;
}
}
return Large;
}

Tuesday, April 8, 2008

C# : What is the difference between ref and out?

As far as I understood, the ref is like in/out and out is just out. What I meant is that you can send a value in to a function using a ref parameter but you can't send a value using an out parameter. Out parameter can be used only for returning a value from a function. Also the ref parameters should be initialized before passing to the function.

Thursday, April 3, 2008

C# : Text box text is not getting refreshed

I had to do a code like the one shown below

txtSample.Text = "Text Sample1";

//few lines of code

txtSample.Text = "Text Sample2";

But it was showing only 'Text Sample2'.

I was looking for a solution and I found that I need to invalidate the rectangle so that the new text will be displayed. There is a method Invalidate() associated with all the controls. But it was not working for me. You need to use the Refresh() method if you need the control fully painted before you take the next step.

Wednesday, April 2, 2008