0% found this document useful (0 votes)
332 views25 pages

Final Exam (C#)

Uploaded by

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

Final Exam (C#)

Uploaded by

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

1

Chapter(13)
Strings and Text Processing
1. Find all occurrences of a particular substring within another string. (5
marks)
using System;
class SubstringWithinAnotherString
{
static void Main(string[] args)
{
string quote = "The main intent of the \"Intro C#\"" +
" book is to introduce the C# programming to newbies.";
string keyword = "C#";
int index = quote.IndexOf(keyword);
while (index != -1)
{
Console.WriteLine("{0} found at index: {1}", keyword, index);
index = quote.IndexOf(keyword, index + 1);
}
}
}
2. Write down a console program to split a string by a separator or an array
of possible separators. (5 marks)
using System;
class SplittingtheStringBySeparator
{
static void Main(string[] args)
{
string listOfStudents = "MyatPan, KyawKyi, ZawKyi, NyanKyi";
char[] separators = new char[] { ' ', ',', '.' };
string[] studentsArr = listOfStudents.Split(separators);
foreach (string stu in studentsArr)
{
if (stu != "")
{
Console.WriteLine(stu);
}
}
}
}

3. Write a program that reads a string, reverse it and prints it to the console.
For example: "introduction" >>> "noitcudortni". (5marks)
using System;
class ReverseString
{
static void Main(string[] args)
{
string text = "introduction";
2

string reversed = ReverseText(text);


Console.WriteLine(reversed);

}
static string ReverseText(string text)
{
StringBuilder sb = new StringBuilder();
for (int i = text.Length - 1; i >= 0; i--)
{
sb.Append(text[i]);

}
return sb.ToString();
}
}

4. How to extract all capital Letters from a text using c# program.( 5marks)
using System;
namespace ConsoleAppExtrectUpperCase
{
class Program
{
static void Main(string[] args)
{
string line = "Extracting All Capital Letters from a Text";
string upChar = ExtractCapitals(line);
Console.WriteLine(upChar); //EACLT
}
public static string ExtractCapitals(string str)
{
StringBuilder result = new StringBuilder();
for (int i = 0; i < str.Length; i++)
{
char ch = str[i];
if (char.IsUpper(ch))
{
result.Append(ch);
}
}
return result.ToString();
}
}
}
3

5. Write a program that detects how many times a substring is contained in


the text. For example, let’s look for the substring "in" in the text: (5marks)

We are living in a yellow submarine. We don't have anything else. Inside the
submarine is very tight. So we are drinking all the day. We will move out of it
in 5 days.

using System;
class Program
{

static void Main(string[] args)


{

string mainString = "We are living in a yellow submarine."+


"We don't have anything else. Inside the submarine is very tight." +
"We will move out of it in 5 days.";
string findString = "in";
int strt = 0;
int count = 0;
int idx = -1;

while (strt != -1)


{
strt = mainString.IndexOf(findString, idx + 1);
count += 1;
idx = strt;
}
Console.Write("The string '{0}' occurs " + count + " times.\n",
findString);
}
}

Chapter-14
Defining Classes
6. Define a class Student, which contains the following information about
students: full name, course, subject, university, e-mail and phone number.
(5marks)
using System;
class Student
{
string stuName,course,subject,university,email;
4

string phNumber;
public Student(string name, string cu, string sub, string uni, string
em, string ph)
{
stuName = name;
course = cu;
subject = sub;
university = uni;
email = em;
phNumber = ph;
}
static void Main(string[] args)
{
Student stu = new Student("Bo Bo",
"IT","Programming","GTC(MDY)","[email protected]","0940000123");
Console.WriteLine("Student Name : " + stu.stuName);
Console.WriteLine("Course : " + stu.course);
Console.WriteLine("Subject : " + stu.subject);
Console.WriteLine("University : " + stu.university);
Console.WriteLine("Email : " + stu.email);
Console.WriteLine("Phone No. : " + stu.phNumber);

7. Create a class that quickly calculates the square root of an integer and
returns the whole part of the result, which is also an integer. (10 marks)
using System;
namespace ConsoleAppSquareCalculateCh14
{
static class SqrtPrecalculated
{
public const int MaxValue = 1000;
private static int[] sqrtValues;
static SqrtPrecalculated()
{
sqrtValues = new int[MaxValue + 1];
for (int i = 0; i < sqrtValues.Length; i++)
{
sqrtValues[i] = (int)Math.Sqrt(i);
}
}
public static int GetSqrt(int value)
{
if ((value < 0) || (value > MaxValue))
{
throw new ArgumentOutOfRangeException(String.Format("The
argument should be in range [0...{0}].",MaxValue));
}
return sqrtValues[value];
}
}
5

class SqrtTest
{
static void Main()
{
Console.WriteLine(SqrtPrecalculated.GetSqrt(254));
}
}
}
8. Write a program that customers can order different amounts of coffee, as
the coffee machine has predefined values “small” – 100 ml, “normal” –
150 ml and “double” – 300 ml. (10 marks)
using System;
namespace ConsoleAppEnumCoffeeExample
{
public enum CoffeeSize
{
Small = 100, Normal = 150, Double = 300
}
public class Coffee
{
public CoffeeSize size;
public Coffee(CoffeeSize size)
{
this.size = size;
}
public CoffeeSize Size
{
get { return size; }
}
static void Main()
{
Coffee normalCoffee = new
Coffee(CoffeeSize.Normal);
Coffee doubleCoffee = new
Coffee(CoffeeSize.Double);
Console.WriteLine("The {0} coffee is {1} ml.",
normalCoffee.Size, (int)normalCoffee.Size);
Console.WriteLine("The {0} coffee is {1} ml.",
doubleCoffee.Size, (int)doubleCoffee.Size);
}
}
}

9. Write a program to create a class that describes a shelter for homeless


animals – AnimalShelter. This class has a specific number of free cells,
which determines the number of animals, which could find refuge in the
shelter. ( 20 marks)
using System;
public class Dog
{

}
public class AnimalShelter
6

{
private const int DefaultPlacesCount = 20;
private Dog[] animalList;
private int usedPlaces;
public AnimalShelter() : this(DefaultPlacesCount)
{
}
public AnimalShelter(int placesCount)
{
this.animalList = new Dog[placesCount];
this.usedPlaces = 0;
}
public void Shelter(Dog newAnimal)
{
if (this.usedPlaces >= this.animalList.Length)
{
throw new InvalidOperationException("Shelter is full.");
}
this.animalList[this.usedPlaces] = newAnimal;
this.usedPlaces++;
}
public Dog Release(int index)
{
if (index < 0 || index >= this.usedPlaces)
{
throw new ArgumentOutOfRangeException(
"Invalid cell index: " + index);
}
Dog releasedAnimal = this.animalList[index];
for (int i = index; i < this.usedPlaces - 1; i++)
{
this.animalList[i] = this.animalList[i + 1];
}
this.animalList[this.usedPlaces - 1] = null;
this.usedPlaces--;
return releasedAnimal;
}
static void Main()
{
AnimalShelter dogsShelter = new AnimalShelter(10);
Dog dog1 = new Dog();
Dog dog2 = new Dog();
Dog dog3 = new Dog();

dogsShelter.Shelter(dog1);
dogsShelter.Shelter(dog2);
dogsShelter.Shelter(dog3);

dogsShelter.Release(1); // Releasing dog2


Console.WriteLine("Now Animal Shelter is used
"+dogsShelter.usedPlaces + " places");

}
7

10. Write a program an inner (nested) class is called a class that is declared
inside the body of another class. (10 marks)
using System;
public class OuterClass
{
private string name;
private OuterClass(string name)
{
this.name = name;
}
private class NestedClass
{
private string name;
private OuterClass parent;
public NestedClass(OuterClass parent, string name)
{
this.parent = parent;
this.name = name;
}
public void PrintNames()
{
Console.WriteLine("Nested name: " + this.name);
Console.WriteLine("Outer name: " + this.parent.name);
}
}
static void Main()
{
OuterClass outerClass = new OuterClass("outer");
NestedClass nestedClass = new
OuterClass.NestedClass(outerClass, "nested");
nestedClass.PrintNames();
}
}

11. Write a program define a class with name is Dog here own all the element
and results the element. (20 marks)
using System;
using System.IO;
class Program
{
public class Dog
{
public string name;
public Dog ()
{
8

}
public Dog(string name)
{
this.name = name;
}
public string Name
{
get { return name; }
set { name = value; }
}

public void Bark()


{
Console.WriteLine("{0} said: Wow-wow!",
name ?? "[unnamed dog]");
}
}

static void Main(string[] args)


{
string firstDogName = null;
Console.Write("Enter first dog name: ");
firstDogName = Console.ReadLine();

Dog firstDog = new Dog(firstDogName);

Dog secondDog = new Dog();


Console.Write("Enter second dog name: ");
string secondDogName = Console.ReadLine();

secondDog.Name = secondDogName;

Dog thirdDog = new Dog();


Dog[] dogs = new Dog[] { firstDog, secondDog, thirdDog };
foreach (Dog dog in dogs)
{
dog.Bark();
}
}
}
Chapter 15
Text Files
12. Write a program to read the entire text file line by line and print the read
text on to the console. (or)
Write a program that reads the contents of a text file and inserts the line
numbers at the beginning of each line, then rewrites the file contents.(5
marks)
using System;
using System.IO;
class FileReader
{
9

static void Main(string[] args)


{
string fileName = @"D:\Sample.txt";

StreamReader reader = new StreamReader(fileName);


int lineNumber = 0;
string line = reader.ReadLine();
while (line != null)
{
lineNumber++;
Console.WriteLine("Line {0} : {1}", lineNumber, line);
line = reader.ReadLine();
}
reader.Close();
}
}

13. Write a program to enroll in a text file the numbers from 1 to 20, each
number on a separate line. (5marks)
using System;
using System.IO;
class FileWriter
{
static void Main(string[] args)
{
StreamWriter writer = new StreamWriter(@"D:\numbers.txt");
using (writer)
{
for (int i = 1; i <= 20; i++)
{
writer.WriteLine(i);
}
}
}
}

14. Write a program how to implement a simple program that counts how
many times a substring occurs in a text file. In the example, let’s look for
the substring "C#" in a text file as follows:
This is our "Intro to Programming in C#" book. In it you will learn the
basics of C# programming. You will find out how nice C# is. (20 marks)
using System;
using System.IO;
10

class Program
{
static void Main(string[] args)
{
string filename = @"D:\Sample txt files for C#\Sample.txt";
string word = "C#";
try
{
StreamReader reader = new StreamReader (filename);
{
int occurrences = 0;
string line = reader.ReadLine();
while (line != null)
{
int index = line.IndexOf(word);
while (index != -1)
{
occurrences++;
index = line.IndexOf(word, (index + 1));
}
line = reader.ReadLine();
}
Console.WriteLine(
"The word {0} occurs {1} times.", word, occurrences);
}
}
catch (FileNotFoundException)
{
Console.Error.WriteLine("Cannot find file {0}",filename);
}
catch (IOException)
{
Console.Error.WriteLine("Cannot read file {0}", filename);
}
}
}
15. Write a program that reads a text file and prints its odd lines on the
console. (10 marks)
using System;
using System.IO;
class Program
{
static void Main(string[] args)
{
string fileName = @"D:\Sample txt files for C#\oddLine.txt ";
try
{
StreamReader reader = new StreamReader(fileName);
using (reader)
{
int lineNumber = 0;
11

string line = reader.ReadLine();


while (line != null)
{
lineNumber++;
if ((lineNumber % 2 )== 1)
{
Console.WriteLine("Line {0}: {1}", lineNumber, line);

}
line = reader.ReadLine();
}
}
}
catch (FileNotFoundException)
{
Console.Error.WriteLine("File cannot find {0}",fileName);
}
}
}
16. Write a program that joins two text files and records the results in a third
file. (20 marks)
using System;
using System.IO;
class Program
{
static void Main(string[] args)
{
string firstFile =@"D:\Sample txt files for C#\FirstFile.txt";
string secondFile = @"D:\Sample txt files for C#\SecondFile.txt";
string resultFile = @"D:\Sample txt files for C#\ResultFile.txt";

StreamReader reader = new StreamReader(firstFile);


StreamReader reader2 = new StreamReader(secondFile);
StreamWriter writer = new StreamWriter(resultFile);
string line = reader.ReadLine();

using (reader)
{
while ( line != null)
{
writer.WriteLine(line);

line = reader.ReadLine();

}
string line2 = reader2.ReadLine();
using (reader2)
{
12

while (line2 != null)


{
writer.WriteLine(line2);

line2 = reader2.ReadLine();
}
}
using (writer)
{
writer.WriteLine(line);
writer.WriteLine(line2);
}
}
}
17. Write a program that compares two text files with the same number of
rows line by line and prints the number of equal and the number of
different lines.(20 marks)
using System;
using System.IO;
class ConsoleAppCompareTwoTextFiles
{
static int lineCountForF1 = 0;
static int lineCountForF2 = 0;
static void Main(string[] args)
{
StreamReader reader1 = new StreamReader(@"D:\Sample txt
files for C#\FirstFile.txt");
StreamReader reader2 = new StreamReader(@"D:\Sample txt
files for C#\SecondFile.txt");
using (reader1)
{
string line = reader1.ReadLine();
while (line != null)
{
lineCountForF1++;
line = reader1.ReadLine();
}
}
using (reader2)
{
string line = reader2.ReadLine();
while (line != null)
{
lineCountForF2++;
line = reader2.ReadLine();
}
}
if (lineCountForF1 == lineCountForF2)
{
Console.WriteLine("Same number of Line");
}
else
13

Console.WriteLine("Different Line");
}
}
18. Write a program that reads a list of names from a text file, arranges them
in alphabetical order, and writes them to another file. The lines are written
one per row. (20 marks)
using System;
using System.IO;
class ReadnameAndWriteOrder
{
static void Main(string[] args)
{
string fileName = @"D:\Sample txt files for C#\ListOfName.txt";
string fileName2 = @"D:\Sample txt files for C#\
OrderOfName.txt";
try
{
StreamReader reader = new StreamReader(fileName);
StreamWriter writer = new StreamWriter(fileName2);
List<string> names = new List<string>();
using (reader)
{
string line = reader.ReadLine();
while (line != null)
{
names.Add(line);
line = reader.ReadLine();
}
names.Sort();
}
using (writer)
{
foreach (string s in names)
{
writer.WriteLine(s);
}
}
}
catch (FileNotFoundException)
{
Console.Error.WriteLine("File not Found");
}
}
}

Chapter 16
14

Linear Data Structures


19. Write a program to implement the operation adding a new element and
display the existing element from a array list. (20 marks)
using System;
using System.Collections.Generic;
namespace shlist
{
public class CustomArrayList<T>
{
private T[] arr;
private int count;
public int Count
{
get
{
return this.count;
}
}
private const int INITIAL_CAPACITY = 4;
public CustomArrayList(int capacity = INITIAL_CAPACITY)
{
this.arr = new T[capacity];
this.count = 0;
}
public void Add(T item)
{
GrowIfArrIsFull();
this.arr[this.count] = item;
this.count++;
}
private void GrowIfArrIsFull()
{
if (this.count + 1 > this.arr.Length)
{
T[] extendedArr = new T[this.arr.Length * 2];
15

Array.Copy(this.arr, extendedArr, this.count);


this.arr = extendedArr;
}
}
public T this[int index]
{
get
{
if (index >= this.count || index < 0)
{
throw new ArgumentOutOfRangeException(
"Invalid index: " + index);
}
return this.arr[index];
}
set
{
if (index >= this.count || index < 0)
{
throw new ArgumentOutOfRangeException(
"Invalid index: " + index);
}
this.arr[index] = value;
}
}
}
class CustomArrayListTest
{
static void Main(string[] args)
{
CustomArrayList<string> shoppingList =
new CustomArrayList<string>();
shoppingList.Add("Milk");
shoppingList.Add("Honey");
16

shoppingList.Add("Olives");
shoppingList.Add("Water");
shoppingList.Add("Beer");
Console.WriteLine("We need to buy:");
for (int i = 0; i < shoppingList.Count; i++)
{
Console.WriteLine(shoppingList[i]);
}
}
}
}
20. Write a console program finding the prime numbers in a certain interval.
(15 marks)
using System;
using System.Collections.Generic;
class Program
{
static List<int> GetPrimes(int start, int end)
{
List<int> primesList = new List<int>();
for (int num = start; num <= end; num++)
{
bool prime = true;
double numSqrt = Math.Sqrt(num);
for (int div = 2; div <= numSqrt; div++)
{
if (num % div == 0)
{
prime = false;
break;
}
}
if (prime)
{
primesList.Add(num);
}
}
return primesList;
}

static void Main(string[] args)


{
List<int> primes = GetPrimes(200, 300);
foreach (var item in primes)
{
Console.Write("{0} ", item);
}
17

}
}
}

21. Write a console program for union and intersection list and print list for
union and intersection. (20 marks)
using System;
using System.Collections.Generic;
namespace ConsoleAppUnionAndInterSet
{
class Program
{
static List<int> Union( List<int> firstList, List<int> secondList)
{
List<int> union = new List<int>();
union.AddRange(firstList);
foreach (var item in secondList)
{
if (!union.Contains(item))
{
union.Add(item);
}
}
return union;
}
static List<int> Intersect(List<int> firstList, List<int> secondList)
{
List<int> intersect = new List<int>();
foreach (var item in firstList)
{
if (secondList.Contains(item))
{
intersect.Add(item);
}
}
return intersect;
}
static void PrintList(List<int> list)
{
Console.Write("{ ");
foreach (var item in list)
{
Console.Write(item);
Console.Write(" ");
}
Console.WriteLine("}");
}
static void Main(string[] args)
{
List<int> firstList = new List<int>();
firstList.Add(1);
firstList.Add(2);
firstList.Add(3);
18

firstList.Add(4);
firstList.Add(5);
Console.Write("firstList = ");
PrintList(firstList);

List<int> secondList = new List<int>();


secondList.Add(2);
secondList.Add(4);
secondList.Add(6);
Console.Write("secondList = ");
PrintList(secondList);

List<int> unionList = Union(firstList, secondList);


Console.Write("union = ");
PrintList(unionList);
List<int> intersectList =
Intersect(firstList, secondList);
Console.Write("intersect = ");
PrintList(intersectList);
}
}
}

22. Write a console program for a simple example on how to use stack. (5
marks)
using System;
using System.Collections.Generic;
namespace ConsoleAppStack
{
class Program
{
static void Main(string[] args)
{
Stack<string> stack = new Stack<string>();
stack.Push("1. John");
stack.Push("2. Nicolas");
stack.Push("3. Mary");
stack.Push("4. George");
Console.WriteLine("Top " + stack.Peek());
Console.WriteLine(stack.Count);
while (stack.Count > 0)
{
string personName = stack.Pop();
Console.WriteLine(personName);
}
}
}
23. Write a program by using console to check whether the brackets are put
correctly for given expression 1 + (3 + 2 - (2+3)*4 - ((3+1)*(4-2))). (15
marks)
using System;
using System.Collections.Generic;
19

namespace ConsoleAppCheckBrackets
{
class Program
{
static void Main(string[] args)
{
string expression = "1 + (3 + 2 - (2+3)*4 - ((3+1)*(4-2)))";
Stack<int> stack = new Stack<int>();
bool correctBrackets = true;
for (int index = 0; index < expression.Length; index++)
{
char ch = expression[index];
if (ch == '(')
{
stack.Push(index);
}
else if (ch == ')')
{
if (stack.Count == 0)
{
correctBrackets = false;
break;
}
stack.Pop();
}
}
if (stack.Count != 0)
{
correctBrackets = false;
}
Console.WriteLine("Are the brackets correct? " +
correctBrackets);

}
}
}
24. Create a queue and add several elements to it and retrieve all elements
and print them on the console. (5marks)
using System;
using System.Collections.Generic;
namespace ConsoleAppQueue
{
class Program
{
static void Main(string[] args)
{
Queue<string> queue = new Queue<string>();
queue.Enqueue("Message One");
queue.Enqueue("Message Two");
queue.Enqueue("Message Three");
queue.Enqueue("Message Four");
20

Console.WriteLine("Total number of Meaasge: " + queue.Count);


while (queue.Count > 0)
{
string msg = queue.Dequeue();
Console.WriteLine(msg);
}
}
}
}
MCQ
1. What is the String in C# meant for?
a) Variable
b) Character Array
c) Object
d) Class
2. To perform comparison operation on strings supported operations are
____________
a) Compare()
b) Equals()
c) Assignment ‘==’ operator
d) All of the mentioned
3. Correct way to convert a string to uppercase using string class
method()?
a) Upper()
b) ToUpper()
c) Object.ToUpper()
d) None of the mentioned
4. What will be the output of the following C# code?
static void Main(string[] args)
{
String obj = "hello";
String obj1 = "world";
String obj2 = obj;
Console.WriteLine (obj.Equals(obj2) + " " + obj2.CompareTo(obj)
);
Console.ReadLine();
}
a) True True
b) False False
c) True 0
d) False 1
21

5. What will be the output of the following C# code?


static void Main(string[] args)
{
String obj = "hello";
String obj1 = "worn";
String obj2 = obj;
Console.WriteLine(obj + " " + (obj1.Replace('w' ,'c')));
Console.ReadLine();
}
a) hello hello
b) hello worn
c) hello corn
d) hello
6. When an object is returned by a function, a _______________ is
automatically created to hold the return value.
a) Temporary object
b) Virtual object
c) New object
d) Data member

7. Which of the following is the correct way to create an object of the class
Sample?

1. Sample s = new Sample();


2. Sample s;
3. Sample s; s = new Sample();
4. s = new Sample();

a) 1,3
b) 2,4
c) 1,2,3
d) 1,4

8. The this reference gets created when a member function (non-shared) of a


class is called.
A. True
B. False

9. Which keyword is used to define a class in C#?

a) Class
b) class
c) System.Class
d) OOPS.class

10. Which is the correct way to declare an object of the class in C#?
22

a) Class_Name Object_Name = new Class_Name();


b) Class_Name Object_Name;
c) new Object_Name as Class_Name();
d) Both A and B

11.Which operator is used to access variables/fields inside a class in C#?

a) Arrow Operator (->)


b) Dot Operator (.)
c) Greater Than (>)
d) Dot and Greater Than (.>)

12. Which is not a type of constructor in C#?

a) Static Constructor
b) Private Constructor
c) Body Constructor
d) Parameterized Constructor

13. How many types of access modifiers in C#?

a) 2
b) 3
c) 4
d) 5

14. What does the access modifier do in C#?

a) To maintain the syntax


b) To define a variable inside the class
c) To access the variables defined inside the class
d) To control the visibility of class members

15. Which C# concept has the capability of an object to take number of


different forms and hence display behaviour as accordingly?

a) Polymorphism
b) Encapsulation
c) Abstraction
d) None of the above

16. What will be the output of the following C# code?

using System;
namespace MyApplication {
class Program {
static void Main(string[] args) {
string[] mobiles = {"iPhone", "Samsung", "Vivo"};
Console.WriteLine(mobiles[-1]);
23

}
}
}

a) None
b) Warning
c) Exception
d) System.String[]

17. Which statement is correct about the following C# statement?

int[] x= {10, 20, 30};

a) 'x' is a reference to the array created on stack


b) 'x' is a reference to an object created on stack
c) 'x' is a reference to an object of a 'System.Array' class
d) None of the above

18. What will be the output of the following C# code?

using System;
namespace MyApplication {
class Program {
static void Main(string[] args) {
string[] mobiles = {"iPhone", "Samsung", "Vivo"};
Console.WriteLine(mobiles[0] + mobiles[2]);
}}}

a) iPhoneVivo
b) iPhone+Vivo
c) Exception
d) iPhone Vivo

19. Which array method is used to sort an array alphabetically or in an


ascending order in C#?

a) sort()
b) sorting()
c) Sort()
d) Sorting()

20. ……….. is used when you need last-in, first-out access of items.

a) List
b) Stack
c) Array
d) Queue

21. ……….. is used when you need a first-in, first-out access of items.

a) List
b) Stack
c) Array
24

d) Queue

22. The ……….. property gets or sets the number of elements that the
ArrayList can contain.

a) Count
b) Item
c) Capacity
d) Length

23. The act of adding values into a stack is called,

a) Pop()
b) Push()
c) Peek()
d) Clear()

24. Which data type is used to create a variable that should store text?

a) myString
b) string
c) str
d) Txt

25. Which property can be used to find the length of a string?

a) length
b) Length
c) getLength()
d) length()

26. To declare an array in C#, define the variable type with:

a) [ ]
b) { }
c) ( )

27. To declare an array in C#, define the variable type with:

a) MyMethod()
b) MyMethod
c) (MyMethod)
d) myMethod[]

28. What is the correct way to create an object called myObj of MyClass?

a) New myObj = MyClass();


b) class myObj = new MyClass();
c) class MyClass = new myObj();
25

d) MyClass myObj = new MyClass();

29. What is the name of the 'special' class that represents a group of
constants?
a) emum
b) special
c) const
d) void

30. Which access modifier makes the code only accessible within the same
class?
a) abstract
b) private
c) public
d) final

You might also like