안녕하세요 저는 C#을 배우고 있습니다.Main()에서 메서드를 호출 할 수 없습니다?
인스턴스에서 내 메서드를 호출 할 때 인텔리전스에 대한 옵션이 표시되지 않고 입력해야합니다. . 구축하려고 할 때
는 또한 현재 두 가지 오류가 있습니다
이 이1) " '문자열 []' 'LastWriteTime'없이 확장 방법에 대한 정의를 포함하지 않는 'LastWriteTime'는의 첫 번째 인수를 받아들이는 'string []'을 (를) 찾을 수 있습니다. "
2).;
단서가 크게 감상 할 수있다 "회원 'MyClass.Move_Modified_Files이() 인스턴스를 참조하여 액세스 할 수 없습니다 대신 형 이름으로 자격을!"
namespace File_Mover
{
public class MyClass
{
public static string src = @"C:\Users\Bold Defiance\Desktop\FolderA";
public static string dst = @"C:\Users\Bold Defiance\Desktop\FolderB";
public static string[] files = System.IO.Directory.GetFiles(src, "*.txt");
public static void Move_Modified_Files()
{
try
{
if (files.LastWriteTime.Date == DateTime.Today.Date)
{
File.Move(src, dst);
Console.WriteLine("Modified files in {0} were moved to {1}", src, dst);
}
else
{
Console.WriteLine("No new or modified files were created today.");
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}
class Program
{
static void Main(string[] args)
{
MyClass cls = new MyClass();
cls.Move_Modified_Files();
}
}
}
또한, 'File.Move'는 디렉토리에 대한 작업을 시도합니다. 예외가 발생하지 않으면 폴더 자체를 다른 폴더로 이동합니다. 'DirectoryInfo.EnumerateFiles'는 아마도 LastWriteTime을 직접 질의하고 MoveTo에 접근하기 위해 FileInfo 객체를 반환하고 더 큰 디렉토리를 위해 지연 평가를하는 것이 더 적합 할 것입니다. – pinkfloydx33