c#输入输出

This section contains aptitude questions and answers on C# Basic Input/output Aptitude Questions and Answers.

本节包含有关C#基本输入/输出能力倾向问题和答案的能力倾向问题和答案。

1) What will be the output of following program?

static void Main(string[] args)
{int a = 10, b = 20;
Console.WriteLine("{0},{0}", a, b);
}

  1. 10,10

  2. 10,20

  3. 20,20

  4. 20,10

Answer & Explanation

Correct answer: 1
10,10

There are two variables a and b, but while printing the values of a and b, we are using the same placeholder {0}, that will print the value of the first variable. Thus the output is 10,10.

1)以下程序的输出是什么?

  1. 10,10

  2. 10,20

  3. 20,20

  4. 20,10

答案与解释

正确答案:1
10,10

有两个变量a和b ,但是在打印a和b的值时,我们使用的是相同的占位符{0} ,它将打印第一个变量的值。 因此输出为10,10

2) What will be the output of following program?

static void Main(string[] args)
{int a = 10, b = 20;
Console.WriteLine("{0}+{1}", a, b);
}

  1. 30

  2. 20+20

  3. 10+10

  4. 10+20

Answer & Explanation

Correct answer: 4
10+20

In the statement Console.WriteLine("{0}+{1}", a, b); {0} is the placeholder for variable a and {1} is the placeholder for variable b, {0}+{1} will not perform any operation, values of a and b will be printed at the place of {0} and {1}. Thus, the output will be 10+20.

2)以下程序的输出是什么?

  1. 30

  2. 20 + 20

  3. 10 + 10

  4. 10 + 20

答案与解释

正确答案:4
10 + 20

在语句Console.WriteLine(“ {0} + {1}”,a,b);中。 {0}是变量a的占位符, {1}是变量b的占位符, {0} + {1}将不执行任何操作, a和b的值将被打印在{0}和{ 1} 。 因此,输出将为10 + 20

3) What will be the output of following program?

static void Main(string[] args)
{Console.WriteLine(Console.Write("Hello"));
}

  1. Error

  2. 6Hello

  3. Hello6

  4. Hello5

Answer & Explanation

Correct answer: 1
Error

Console.Write() and Console.WriteLine() methods do not return any value, their return type is void. Thus, the statement will not be executed and an error "cannot convert void to bool" will return.

3)以下程序的输出是什么?

  1. 错误

  2. 6你好

  3. 你好6

  4. 你好5

答案与解释

正确答案:1
错误

Console.Write()和Console.WriteLine()方法不返回任何值,它们的返回类型为void 。 因此,该语句将不会执行,并且将返回错误“无法将void转换为bool”

4) What will be the output of following program?

static void Main(string[] args)
{int a = 10, b = 10;
Console.WriteLine(a == b);
}

  1. 1

  2. a==b

  3. True

  4. true

Answer & Explanation

Correct answer: 3
True

a==b is a Boolean expression, values of a and b are the same. Thus, the output will be True.

4)以下程序的输出是什么?

  1. 1个

  2. a == b

  3. 真正

  4. 真正

答案与解释

正确答案:3
真正

a == b是布尔表达式, a和b的值相同。 因此,输出将为True

5) What will be the output of the following program, if the input is "Hello world!"?

static void Main(string[] args)
{string text = "";
text = Console.ReadLine();
Console.WriteLine(text);
}

  1. Hello

  2. Hello world!

  3. Helloworld!

  4. None

Answer & Explanation

Correct answer: 2
Hello world!

Here, text is a string variable, and Console.ReadLine() method is used to read the string with spaces. Thus, there is no issue in this code and output will be "Hello world!".

5)如果输入是“ Hello world!”,以下程序的输出是什么?

  1. 你好

  2. 你好,世界!

  3. 你好,世界!

  4. 没有

答案与解释

正确答案:2
你好,世界!

在这里, text是一个字符串变量, Console.ReadLine()方法用于读取带空格的字符串。 因此,这段代码没有问题,输出将是“ Hello world!”。

翻译自: https://www.includehelp.com/dot-net/c-sharp-basic-input-output-aptitude-questions-and-answers.aspx

c#输入输出

c#输入输出_C#基本输入/输出能力问题和答案相关推荐

  1. JAVA订单的输入输出_Java的输入/输出操作

    Java的输入\输出机制 计算机的基本功能就是通过输入输出设备与外部其他设备尽心数据的交互,从其他设备读入数据叫做输入操作,将计算机内的数据写入到其他设备叫做输出操作.可以向计算机发送数据.又可以接受 ...

  2. c语言 结构体的输入输出_C语言的控制结构和输入输出

    c语言 结构体的输入输出 Control Structure in C defines how the statements in the program are going to execute. ...

  3. c++中整形输入逗号_C语言输入和输出方法amp;技巧详解

    引言 今天刷题,写了好久写完了,一提交0分,改了好久没改对1分,看了一下别人的代码,又简洁又直观,代码量又少,还是满分,心理不平衡了,仔细看了一下,对输入输出的处理处理的好好.吃了这方面的亏,干脆借着 ...

  4. 年月日_C++计算输入的年月日是这一年的第几天

    C++计算输入的年月日是这一年的第几天 #include<stdio.h> int leap(int a) { if(a%4==0&&a%100!=0||a%400==0) ...

  5. c++ 字符串合并_C语言输入字符和字符串(所有函数大汇总)

    C语言输入字符和字符串(所有函数大汇总) C语言有多个函数可以从键盘获得用户输入,它们分别是: scanf():和 printf() 类似,scanf() 可以输入多种类型的数据. getchar() ...

  6. 描述:给出若干个数,将数字存储在数组中,然后使用插入排序,按照升序排列出输出数字。输入一个整数n表示有n个数,接着输入这n个数。按照升序输出这n个数。输入输出示例:输入:53 2

    #include<stdio.h> int main() {int k, x, N,i;scanf("%d", &N);int a[100];//随便定义了一个 ...

  7. 微型计算机控制数字量输入输出,计算机控制系统输入/输出通道

    在微机控制系统中,为了实现对生产过程的控制,要将对象的各种测量参数,按要求的方式送人微机.微机经过运算.处理后,将结果以数字量的形式输出,此时也要把该输出变换为适合于对生产过程进行控制的量.所以在微机 ...

  8. 第四章 C语言输入输出_C语言数据输出大汇总以及轻量进阶

    在C语言中,有三个函数可以用来在显示器上输出数据,它们分别是: puts():只能输出字符串,并且输出结束后会自动换行,在<第一个C语言程序>中已经进行了介绍. putchar():只能输 ...

  9. c语言识别按了esc键_c语言输入esc

    <C语言及程序设计>实践项目--敲了哪一个键? 返回:贺老师课程教学链接 [项目2-敲了哪一个键?] 在应用中,常需要检测键盘上敲了哪一个键.每个输入的键都对应一个键值(我们熟悉的字母.数 ...

最新文章

  1. java递归url目录_Java递归实现某个目录下所有文件和目录
  2. MapReduce运行原理和过程
  3. json字符串与对象互相转换
  4. eclipse和idea代码通用吗_python能在苹果手机上运行吗
  5. SQL-10 获取所有非manager的员工emp_no
  6. hibernate事务详解
  7. mysql innodb 读加锁,Mysql InnoDB加锁分析
  8. 函数强化练习2(py引入模块、包)
  9. spring-boot-starter-thymeleaf对没有结束符的HTML5标签解析出错
  10. A Deep Learning Tutorial: From Perceptrons to Deep Networks
  11. 恐龙机器人钢索恐龙形态_?四川自贡发现距今1.6亿年恐龙化石 已运抵自贡恐龙博物馆...
  12. 【OpenCV】 ⚠️实战⚠️ 银行卡卡号读取 ☢️建议手收藏☢️
  13. 用计算机术语写毕业寄语,大学毕业寄语(精选50句)
  14. 学java,报班还是自学?
  15. 乐助手电脑版 v3.0.4.33284 官方版
  16. 视频裁剪的软件哪个好用?推荐几个视频裁剪软件给你
  17. AVL树到底是什么?
  18. javascript——从「最被误解的语言」到「最流行的语言」
  19. python字典一键多值如何遍历_[宜配屋]听图阁
  20. php5.3 pear,php-5.3 下安装pear 和 pecl

热门文章

  1. iphone OS、Android、Blackberry OS与Palm OS的比较
  2. win10系统打不开计算机管理,win10电脑任务栏图标一直闪烁,任务管理器打不开...
  3. python的八大排序算法
  4. 性格色彩测试android程序开发之六--activity界面
  5. 百度地图测距 java_【java】改写js百度地图测距方法
  6. jop怎么读音英语怎么说_job是什么意思_ job的翻译_音标_读音_用法_例句_爱词霸在线词典...
  7. 0.2度背后的美国抉择:压不住新能源
  8. 【Lua从青铜到王者基础篇】第一篇:Lua初始教程和环境安装
  9. login: Could not determine audit condition 解决方案
  10. 我的职业生涯(八) 自我疗伤