简体   繁体   English

C# 错误消息:CS1503Argument 1:无法从“void”转换为“bool”

[英]C# Error Message: CS1503Argument 1: cannot convert from 'void' to 'bool'

Does anybody can help me with this issue?有人可以帮我解决这个问题吗? I can't run this code on VS.我无法在 VS 上运行此代码。 It's displaying Cannot convert from "void" to bool.它显示无法从“void”转换为布尔值。 I got stuck here and I can't run this piece of code.我被困在这里,我无法运行这段代码。

Any idea about where the issue is?关于问题出在哪里的任何想法?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;



    namespace HelloWorld
    {
        class Program
        {
            static void Main(string[] args, Array array)
            {
                int[] newAge = { 21, 31, 41, 51, 61 };
                int[] olderAge = { 71, 81, 91, 101, 121 };
                //int i = newAge.Length;


                Console.WriteLine(Array.Copy(newAge, olderAge, 4));
            }


        }
    }

Array.Copy doesn't return anything. Array.Copy不返回任何内容。 So there's nothing to write to the console.所以没有什么可写到控制台的。 Simply remove that Console.WriteLine operation:只需删除该Console.WriteLine操作:

Array.Copy(newAge, olderAge, 4);

Then the question becomes... What do you want to write to the console?那么问题就变成了……想给控制台写什么? For example, if you want to output the contents of one of the arrays, output that:例如,如果要 output 的内容之一是 arrays、output 即:

Console.WriteLine(string.Join(',', newAge));

This would join the values from newAge into a comma-delimited string and write that string to the console.这会将newAge中的值连接到逗号分隔的字符串中,并将该字符串写入控制台。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#无法从void转换为bool - CS1503 - C# Cannot convert from void to bool - CS1503 如何解决此错误“错误 CS1503:参数 1:无法从‘void’转换为‘bool’” - How to resolve this error "error CS1503: Argument 1: cannot convert from 'void' to 'bool'" Console.WriteLine() 错误 CS1503 无法从“void”转换为“bool” - Console.WriteLine() error CS1503 cannot convert from 'void' to 'bool' C# 错误 CS1503 参数 1:无法从“字符串”转换为“字符” - C# Error CS1503 Argument 1: cannot convert from 'string' to 'Character' CS1503 C# 参数 1:无法从“字符串”转换为“System.Data.SqlClient.SqlCommand” - CS1503 C# Argument 1: cannot convert from 'string' to 'System.Data.SqlClient.SqlCommand' C# - CS1503 - 参数 1:无法从“字符串”转换为“整数” - C# - CS1503 - Argument 1: cannot convert from 'string' to 'int' CS1503:参数 1:无法从 'int' 转换为 'byte' C# - CS1503: Argument 1: cannot convert from 'int' to 'byte' C# CS1503 C#参数1:无法从“ System.IO.Stream”转换为“ char []” - CS1503 C# Argument 1: cannot convert from 'System.IO.Stream' to 'char[]' CS1503:参数 2:无法从 'System.Action[*,*,*] 转换为 System.Action[]' C# 2022 - CS1503: Argument 2: Cannot convert from 'System.Action[*,*,*] to System.Action[]' C# 2022 CS1503:参数 1:无法从“方法组”转换为“Action,bool>” - CS1503: Argument 1: cannot convert from 'method group' to 'Action,bool>'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM