0
0
C Sharp (C#)programming~10 mins

Namespaces and using directives in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to include the System namespace.

C Sharp (C#)
using [1];

class Program {
    static void Main() {
        System.Console.WriteLine("Hello World");
    }
}
Drag options to blanks, or click blank then click option'
ASystem
BConsole
CCollections
DText
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Console' instead of 'System' in the using directive.
Forgetting the semicolon after the using statement.
2fill in blank
medium

Complete the code to declare a namespace named MyApp.

C Sharp (C#)
namespace [1] {
    class Program {
        static void Main() {
            System.Console.WriteLine("Inside MyApp namespace");
        }
    }
}
Drag options to blanks, or click blank then click option'
AMyApp
BApplication
CSystem
DConsole
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'System' instead of 'MyApp' as the namespace name.
Omitting the namespace keyword.
3fill in blank
hard

Fix the error by completing the using directive to access List<T>.

C Sharp (C#)
using [1];

class Program {
    static void Main() {
        var list = new List<int>();
        list.Add(1);
        System.Console.WriteLine(list[0]);
    }
}
Drag options to blanks, or click blank then click option'
ASystem.Linq
BSystem.Text
CSystem.IO
DSystem.Collections.Generic
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'System.Text' or 'System.IO' which do not contain List.
Forgetting to add the using directive for the generic collections.
4fill in blank
hard

Fill both blanks to create a namespace and use a directive for Console.

C Sharp (C#)
[1] MyNamespace {
    [2] System;

    class Program {
        static void Main() {
            Console.WriteLine("Hello from MyNamespace");
        }
    }
}
Drag options to blanks, or click blank then click option'
Anamespace
Busing
Cclass
Dpublic
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'namespace' for the first blank.
Omitting the using directive for System.
5fill in blank
hard

Fill all three blanks to declare a namespace, include System, and define a class.

C Sharp (C#)
[1] MyApp {
    [2] System;

    [3] Program {
        static void Main() {
            Console.WriteLine("Welcome to MyApp");
        }
    }
}
Drag options to blanks, or click blank then click option'
Anamespace
Busing
Cclass
Dinterface
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'interface' instead of 'class' for the third blank.
Forgetting the using directive for System.
Omitting the namespace declaration.