Find Twin Prime numbers between 1 and 1000 in C#

A twin prime is a prime number that differs from another prime number by two, for example the twin prime pair (41, 43) or (5,7). Simply means if N is the prime number and N+2 is also prime number then we can say that N and N+2 are the twin prime numbers.
Continue reading “Find Twin Prime numbers between 1 and 1000 in C#”

Replace one date format to another date format in the entire string using Regular expression.

You can use the Regex.Replace method to replace one date format to another date format in the entire string. The following code example uses the Regex.Replace method to replace dates that have the form mm/dd/yy with dates that have the form dd-mm-yy. Continue reading “Replace one date format to another date format in the entire string using Regular expression.”

Can you use the two parameters with Generic class in C#

Yes, You can use more than one type parameters in Generic class.For it you can use the parameters list with comma separated ( if you are new with Generics Read this article Generics in C#) . See the following example:
Continue reading “Can you use the two parameters with Generic class in C#”

How to create Radio Buttons from a String Array in C#

This following example creates radio button controls and set their text from an array of strings programmatically. The example draws the radio button in vertical direction.

private void Form_load(object sender, EventArgs e)
{
    string[] string_Array = new string[3];
 
    string_Array[0] = "USA";
    string_Array[1] = "India";
    string_Array[2] = "Germany";
 
	DrawRadioButtons(string_Array);
}
 
private void DrawRadioButtons(string[] ArrayOfString)
{
    System.Windows.Forms.RadioButton[] btnRadio = new System.Windows.Forms.RadioButton[string_Array.Length];
 
    for (int i = 0; i < ArrayOfString.Length; ++i)
    {
        btnRadio[i] = new RadioButton();
        btnRadio[i].Text = ArrayOfString[i];
        btnRadio[i].Location = new System.Drawing.Point(10, 30 + i * 20);
        this.Controls.Add(btnRadio[i]);
    }
}

See the output on the windows form:
Continue reading “How to create Radio Buttons from a String Array in C#”