c# 命名空间命名规范_C#命名空间能力问题和解答 套装5

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();
        }
    }
}

  1. Syntax error

  2. Hello

  3. Linker error

  4. Runtime exception

Answer & Explanation

Correct answer: 2
Hello

The above code will print "Hello" on console screen.

1)给定代码段的正确输出是什么?
  1. 语法错误

  2. 你好

  3. 链接器错误

  4. 运行时异常

答案与解释

正确答案:2
你好

上面的代码将在控制台屏幕上打印“ Hello”

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();
        }
    }
}

  1. Syntax error

  2. Hello

  3. Linker error

  4. Runtime exception

Answer & Explanation

Correct answer: 2
Hello

The above code will print "Hello" on the console screen.

2)给定代码段的正确输出是什么?
  1. 语法错误

  2. 你好

  3. 链接器错误

  4. 运行时异常

答案与解释

正确答案:2
你好

上面的代码将在控制台屏幕上打印“ Hello”

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();
        }
    }
}

  1. Syntax error

  2. Hello

  3. Linker error

  4. Runtime exception

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. 语法错误

  2. 你好

  3. 链接器错误

  4. 运行时异常

答案与解释

正确答案: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();
        }
    }
}

  1. Syntax error

  2. Hello

  3. Linker error

  4. Runtime exception

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. 语法错误

  2. 你好

  3. 链接器错误

  4. 运行时异常

答案与解释

正确答案:1
语法错误

在C#.NET中,不能在::上使用命名空间。

输出将是

5) In C#.NET, is it possible that we can create a class with the same name in different namespaces?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Yes, it is possible.

5)在C#.NET中,是否可以在不同的命名空间中创建具有相同名称的类?
  1. 没有

答案与解释

正确答案:1

是的,有可能。

翻译自: https://www.includehelp.com/dot-net/csharp-namespace-aptitude-questions-and-answers-5.aspx

c# 命名空间命名规范

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值