c sharp (c#) questions and answers

1. How to check whether a checkbox is checked or not in c sharp (c#)

if (checkBox1.Checked)

MessageBox.Show(“The checkbox1 is checked”);

if (checkBox1.Checked == false)

MessageBox.Show(“The checkbox1 is not checked”);

2.How to create a boolean array in c sharp (c#)

Boolean[] var = new Boolean[8];

3.How to replace string in c sharp (c#)

string str = “hai how r u”;

MessageBox.Show(str);        // o/p : hai how r u

string newstr = str.Replace(“r u”, “do u do”);

MessageBox.Show(newstr);  // o/p : hai how do u do

4. how to take substring in c sharp (c#)

string str=”hai welcome”;

MessageBox.Show(str);        // o/p : hai welcome

string sub = str.Substring(0, 3);

MessageBox.Show(sub);       // o/p : hai

5. how to convert string to bool in c sharp (c#)

string str1 = “true”;

bool var = Convert.ToBoolean(str1);

if (var)

MessageBox.Show(“This is true”);

6. how to reach end of file in c sharp (c#)

StreamReader sr = File.OpenText(textBox1.Text);

Boolean status = true;

while (status)

{

string line = sr.ReadLine();

———————–

—-ur code————

if (sr.EndOfStream)

status = false;

}

7.Check String contains in C sharp (c#)

string str = “hai welcome to india”

if (str.Contains(“to”))

MessageBox.Show(“The given sub string presents”);

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>