c# 命名空間命名規範
1) Can we create more than one namespace in a single source code file?
- Yes
- No
Answer & Explanation
Correct answer: 1
Yes
Yes, we can create multiple namespaces in a single source code file.
1)我們可以在一個源代碼檔案中建立多個名稱空間嗎?
- 是
- 沒有
答案與解釋
正确答案:1 是是的,我們可以在一個源代碼檔案中建立多個名稱空間。
2) What is the correct output of the given code snippet?
using System;
namespace my_namespace1
{
class sample
{
public static void sayHello()
{
Console.WriteLine("Hello");
}
}
}
namespace my_namespace2
{
class program
{
static void Main(string[] args)
{
my_namespace1.sample.sayHello();
}
}
}
- Syntax error
- Hello
- Linker error
- Runtime exception
Answer & Explanation
Correct answer: 2
Hello
The above code will print
"Hello"on the console screen.
2)給定代碼段的正确輸出是什麼?
- 文法錯誤
- 你好
- 連結器錯誤
- 運作時異常
答案與解釋
正确答案:2 你好上面的代碼将在控制台螢幕上列印
“ Hello”。
3) What is the correct output of the given code snippet?
using System;
private namespace my_namespace1
{
class sample
{
public static void sayHello()
{
Console.WriteLine("Hello");
}
}
}
namespace my_namespace2
{
class program
{
static void Main(string[] args)
{
my_namespace1.sample.sayHello();
}
}
}
- Syntax error
- Hello
- Linker error
- Runtime exception
Answer & Explanation
Correct answer: 1
Syntax error
We cannot use a modifier with a namespace.
3)給定代碼段的正确輸出是什麼?
- 文法錯誤
- 你好
- 連結器錯誤
- 運作時異常
答案與解釋
正确答案:1 文法錯誤我們不能将修飾符與名稱空間一起使用。
4) What is the correct output of the given code snippet?
using System;
namespace my_namespace2
{
namespace my_namespace1
{
class sample
{
public static void sayHello()
{
Console.WriteLine("Hello");
}
}
}
class program
{
static void Main(string[] args)
{
sample.sayHello();
}
}
}
- Syntax error
- Hello
- Linker error
- Runtime exception
Answer & Explanation
Correct answer: 1
Syntax error
We cannot use a class without specifying the namespace name.
The output will be,
4)給定代碼段的正确輸出是什麼?
using System ;
namespace my_namespace2
{
namespace my_namespace1
{
class sample
{
public static void sayHello ( )
{
Console . WriteLine ( " Hello " ) ;
}
}
}
class program
{
static void Main ( string [ ] args )
{
sample . sayHello ( ) ;
}
}
}
- 文法錯誤
- 你好
- 連結器錯誤
- 運作時異常
答案與解釋
正确答案:1 文法錯誤如果不指定名稱空間名稱,則不能使用類。
輸出将是
5) What is the correct output of the given code snippet?
using System;
using my_namespace1;
namespace my_namespace2
{
namespace my_namespace1
{
class sample
{
public static void sayHello()
{
Console.WriteLine("Hello");
}
}
}
class program
{
static void Main(string[] args)
{
sample.sayHello();
}
}
}
- Syntax error
- Hello
- Linker error
- Runtime exception
Answer & Explanation
Correct answer: 1
Syntax error
We cannot import inner namespace like this.
The output will be,
5)給定代碼段的正确輸出是什麼?
using System ;
using my_namespace1 ;
namespace my_namespace2
{
namespace my_namespace1
{
class sample
{
public static void sayHello ( )
{
Console . WriteLine ( " Hello " ) ;
}
}
}
class program
{
static void Main ( string [ ] args )
{
sample . sayHello ( ) ;
}
}
}
- 文法錯誤
- 你好
- 連結器錯誤
- 運作時異常
答案與解釋
正确答案:1 文法錯誤我們不能像這樣導入内部名稱空間。
輸出将是
◀ C# Namespace Aptitude | Set 3 C# Namespace Aptitude | Set 5 ▶ #C#命名空間能力| 設定3 C#命名空間能力| 設定5▶
翻譯自: https://www.includehelp.com/dot-net/csharp-namespace-aptitude-questions-and-answers-4.aspx
c# 命名空間命名規範