0% found this document useful (0 votes)
92 views4 pages

Array, String, Regular Expression

The document contains a quiz with 16 multiple choice and short answer questions about event driven programming and regular expressions in C#. Some key points: - Questions cover topics like string methods like Insert, Split, Substring, regular expression patterns for matching names and variable names, quantifiers like *, +, ?, {n}, and using regular expressions to test if strings match patterns. - Code snippets are provided to demonstrate string and array manipulation using methods like Split, Substring, and looping through arrays with foreach. Questions test understanding of the code and its output. - Short answer questions define regular expression patterns and ask to determine if given strings match those patterns or provide alternative patterns for certain scenarios like valid C# variable names

Uploaded by

Mekonnen Fentaw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views4 pages

Array, String, Regular Expression

The document contains a quiz with 16 multiple choice and short answer questions about event driven programming and regular expressions in C#. Some key points: - Questions cover topics like string methods like Insert, Split, Substring, regular expression patterns for matching names and variable names, quantifiers like *, +, ?, {n}, and using regular expressions to test if strings match patterns. - Code snippets are provided to demonstrate string and array manipulation using methods like Split, Substring, and looping through arrays with foreach. Questions test understanding of the code and its output. - Short answer questions define regular expression patterns and ask to determine if given strings match those patterns or provide alternative patterns for certain scenarios like valid C# variable names

Uploaded by

Mekonnen Fentaw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Event Driven Programing Quiz1

1) Which of the following will be the correct output for the C#.NET code snippet given below?
(2pts)
String s1 = Bahir;
String s2;
s2 = s1.Insert(3, Dar Technology);
a) Bahir Dar Technology
d) BahiDar Technologyr
b) BahirDar Technology
e) BahDar Technologyir
c) Bahir Dar Technology
f) None
2) What is the output of the following code?(6pts)
a) int Num1,Num2;
Num1 = 10;
Num2 = 0;
TextBox1.Text = (Num1 / Num2).ToString();
b) int i, LetterCount =0;
String strText ;
String letter = null; ;
strText = "Debugging";
for (i = 1;i< strText.Length-1;i++)
letter = strText.Substring(1,1);
if ( letter.Equals("g") )
LetterCount = LetterCount + 1;
textBox1.Text = "G appears " + LetterCount + " times";
3) Given the following variable declaration: (3pts)
float []results={50,60,45,78,96,84,47,65,89};
Add all array items to the list; named listBox1; using foreach loop
4) Answer the following questions based on the following codes(4pts)
String []array=new String [20];
String strList =Bahir Dar university, Institute of Technology School of
Computing;
array = strList.Split(" ")
a) What is the size of array?
b) List elements of array.

5) Answer the following questions based on the following fragment code(3pts)


int result[]=new int[10];
Write a C# code to change the size of variable result from 10 to 20.
6) What do we mean when we say String is immutable? (2pts)
7) Write a recommended situation to use System.Text.StringBuilder in string processing. (2pts)
8) Which of the following is the correct way to find out the index of the second s in the string
She sells sea shells on the sea-shore? (3pts)
a) String str = "She sells sea shells on the sea-shore";
int i, j;
i = str.LastIndexOf("s");
j = str.IndexOf("s", i - 1);
b) String str = "She sells sea shells on the sea-shore";
int i, j;
i = str.IndexOf("s");
j = str.IndexOf("s", i + 1);
c) String str = "She sells sea shells on the sea-shore";
int i;
i = str.SecondIndexOf("s");
d) String str = "She sells sea shells on the sea-shore";
int i, j;
i = str.FirstIndexOf("s");
j = str.IndexOf("s", i + 1);
9) Write matched if the following string matches the given regular expression anf write not
matched if other wise. (4pts)
String regStr=[a-z]+[@#%][a-z]+;Abebe@bahir dar
a) abebe#bahir dar
e) @bahir dar
b) abebe%bahir dar
f) What is your name?
c) @
g) @#%
d) abebe#
10) Which of the following will be the correct output for the C#.NET code snippet given below?
(3pts)
String s1 = ALL MEN ARE CREATED EQUAL;
String s2;
s2 = s1.Substring(12, 3);
Console.WriteLine(s2);
a) REW
d) CRE
b) rew
e) none
c) CREATED

11) Which of the following will be the correct output for the C#.NET code snippet given below?
(3pts)
String s1 = ALL MEN ARE CREATED EQUAL;
String s2;
s2 = s1.Substring(12);
Console.WriteLine(s2);
a) CREATED EQUAL
d) CRE
b) CREATED EQUAL
e) none
c) CREATED
12) Write the meaning of the following quantifier(6pts)
a) *
d) {n}
b) +
e) {n,}
c) ?
f) {n,m}
13) Write matched if the following string matches the given regular expression anf write not
matched if other wise. (3pts)
String regStr=^[a-z]+[@#%][a-z]+$;
a) Abebe@bahir dar
e) abebe#
b) abebe#bahir dar
f) @bahir dar
c) abebe%bahir dar
g) What is your name?
d) @
h) !@#$
14) Write matched if the following string matches the given regular expression anf write not
matched if other wise. (3pts)
String regStr=[a-z1-9]+;Abebe
a) 123abebe
d) !@#$
b) #abebe
e) <>:{
c) What is your name?
15) Write matched if the following string matches the given regular expression anf write not
matched if other wise. (3pts)
String regStr=^[^<?>,.:;!@#%&*(){}]+$;Abebe
a) 123abebe
d) !@#$
b) #abebe
e) <:>{
c) What is your name?

16) Write regular expression that will be used for the following scenario(6pts)
a) Sequence of character that can be used for C# variable name
b) Begins with sequence of alphabetical letter and followed by sequence of digits or special symbols such
as @#,&*?
c) Consists of sequence of alphabetical letter, digits

You might also like