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# 命名空间命名规范