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

c# 命名空间命名规范

1) Can we create more than one namespace in a single source code file?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Yes, we can create multiple namespaces in a single source code file.

1)我们可以在一个源代码文件中创建多个名称空间吗?
  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();
        }
    }
}

  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;

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

  1. Syntax error

  2. Hello

  3. Linker error

  4. Runtime exception

Answer & Explanation

Correct answer: 1
Syntax error

We cannot use a modifier with a namespace.

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

  2. 你好

  3. 链接器错误

  4. 运行时异常

答案与解释

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

  1. Syntax error

  2. Hello

  3. Linker error

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

  2. 你好

  3. 链接器错误

  4. 运行时异常

答案与解释

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

  1. Syntax error

  2. Hello

  3. Linker error

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

  2. 你好

  3. 链接器错误

  4. 运行时异常

答案与解释

正确答案:1
语法错误

我们不能像这样导入内部名称空间。

输出将是

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

c# 命名空间命名规范

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值