c# 命名空间命名规范
1) What is the correct output of the given code snippet?
using System;
using my_namespace2.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();
}
}
}
Answer & Explanation
Correct answer: 2
Hello
The above code will print "Hello" on console screen.
2) What is the correct output of the given code snippet?
using System;
namespace my_namespace2
{
using my_namespace2.my_namespace1;
namespace my_namespace1
{
class sample
{
public static void sayHello()
{
Console.WriteLine("Hello");
}
}
}
class program
{
static void Main(string[] args)
{
sample.sayHello();
}
}
}
Answer & Explanation
Correct answer: 2
Hello
The above code will print "Hello" on the console screen.
3) 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();
}
}
}
Answer & Explanation
Correct answer: 1
Syntax error
We cannot use using statement at the bottom of our program.
The output would be,
3)给定代码段的正确输出是什么?
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
语法错误
我们不能在程序底部使用using语句。
输出将是
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)
{
my_namespace1::sample.sayHello();
}
}
}
Answer & Explanation
Correct answer: 1
Syntax error
We cannot use a namespace with :: in C#.NET.
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 )
{
my_namespace1 : : sample . sayHello ( ) ;
}
}
}
答案与解释
正确答案:1
语法错误
在C#.NET中,不能在::上使用命名空间。
输出将是
5) In C#.NET, is it possible that we can create a class with the same name in different namespaces?
Answer & Explanation
Correct answer: 1
Yes
Yes, it is possible.
翻译自: https://www.includehelp.com/dot-net/csharp-namespace-aptitude-questions-and-answers-5.aspx
c# 命名空间命名规范