none
why is my code throw me errors on this code RRS feed

  • Question

  • using System;
    using System.IO;

    namespace Class1
    {
        class program
        {
            static void Main(string[] args);
            {
            var sour = 'F:/client.txt';
            var des = 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp/client.txt';

            File.Copy(sour, des);
            Console.WriteLine('Copied');


            }
        }

    Thursday, May 30, 2019 3:19 PM

All replies


  •         static void Main(string[] args);
            {
            var sour = 'F:/client.txt';
            var des = 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp/client.txt';

            File.Copy(sour, des);
            Console.WriteLine('Copied');

            }

    You should always show the errors you get. Don't make us guess.

    The first thing that jumps out from your posted code is that you are using
    single quotes (') around strings. You need to use double quotes (").

    Single quote characters are used for character literals.
    Double quote characters are used for string literals.

    You should also double the backslashes as it is the escape character, or
    use verbatim strings.

    Example:

    var sour = "F:/client.txt";
    var des = @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp/client.txt";
    
    File.Copy(sour, des);
    Console.WriteLine("Copied");

    - Wayne


    • Edited by WayneAKing Thursday, May 30, 2019 5:57 PM
    • Proposed as answer by Mike_999 Thursday, May 30, 2019 8:34 PM
    Thursday, May 30, 2019 4:44 PM

  •         static void Main(string[] args);
            {

    Also remove the semicolon from the end of this line:

    static void Main(string[] args)

    - Wayne

    Thursday, May 30, 2019 4:57 PM
  • Using a Development Environment like Visual Studio would hugely help you find such errors and sort them out. See:

    wizend

    Thursday, May 30, 2019 5:52 PM