I developed this challenge to test one’s knowledge of C Sharp. I am planning on creating several challenges with different skill sets, so don’t get mad if this challenge doesn’t well challenge you... I noticed that most people like short quizzes so this one only contains 5 questions. All of the challenges are clear and concise of what I am asking you to do. No smoke and mirrors here, meaning that none of the code has syntax errors. The purpose of this exercise is to test several OOP concepts and see how much of the C# language you really know. Question #1 – Lets start off Easy… Will the following code snippet compile successfully? What does this question test? - Can this compile without a namespace? Do you have to have an entry point of “static void Main()”? class Test
{
static int Main()
{
System.Console.WriteLine("Developer Challenge");
return 0;
}
}
Answer (select text in box below):
Yes, it will compile successfully.
Question #2 – What is the value of the Console.WriteLine statements?
What does this question test? – Do I understand reference types/value types? If a variable is declared with the @ symbol and its not a reserved keyword does the application compile successfully?
using System;
internal struct MyStruct
{
public int Value;
}
internal class MyClass
{
public int Value;
}
class Test
{
static void Main()
{
MyStruct @struct1 = new MyStruct();
MyStruct @struct2 = @struct1;
@struct2.Value = 100;
MyClass @ref1 = new MyClass();
MyClass @ref2 = @ref1;
@ref2.Value = 100;
Console.WriteLine("Value Type: {0} {1}", @struct1.Value, @struct2.Value);
Console.WriteLine("Reference Type: {0} {1}", @ref1.Value, @ref2.Value);
}
}
Answer (select text in box below):
Value Type: 0 100
Reference Type: 100 100
Question #3 – What is the value of the Console.WriteLine statements?
What does this question test? – Can 2 objects reference the same point in memory?
using System;
class Test
{
static void Main()
{
string s1 = "Testing2";
string t1 = s1;
Console.WriteLine(s1 == t1);
Console.WriteLine((object)s1 == (object)t1);
}
}
Answer (select text in box below):
True
True
Question #4 – What is the value of the Console.WriteLine statements?
What does this question test? – How does the “Stack” work – LIFO or FIFO?
using System;
using System.Collections;
class Test
{
static void Main()
{
Stack a = new Stack(5);
a.Push("1");
a.Push("2");
a.Push("3");
a.Push("4");
a.Push("5");
foreach (var o in a)
{
Console.WriteLine(o);
}
}
}
Answer (select text in box below):
5
4
3
2
1
Question #5 – What is the value of the Console.WriteLine statements?
What does this question test? – Array and General Looping Knowledge.
using System;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int[] J_LIST = new int[5] { 1, 2, 3, 4, 5 };
int K = 10;
int L = 5;
foreach (var J in J_LIST)
{
K = K - J;
L = K + 2 * J;
Console.WriteLine("J = {0, 5} K = {1, 5} L = {2, 5}", J, K, L);
}
Console.ReadLine();
}
}
}
Answer (select text in box below):
J = 1 K = 9 L = 11
J = 2 K = 7 L = 11
J = 3 K = 4 L = 10
J = 4 K = 0 L = 8
J = 5 K = -5 L = 5
Stay Tuned for more challenges!