我有下面的C#代碼:C#編譯錯誤 - 沒有「主」方法適合
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.Cryptography;
namespace command
{
class Program
{
public string DecryptStr(string _source, string _key)
{
string str;
try
{
byte[] bytes1 = Encoding.ASCII.GetBytes(_key.Substring(0, 8));
byte[] bytes2 = Encoding.ASCII.GetBytes(_key.Substring(8, 8));
DES des = (DES)new DESCryptoServiceProvider();
des.Key = bytes1;
des.IV = bytes2;
byte[] buffer = new byte[_source.Length/2];
for (int index = 0; index < _source.Length/2; ++index)
{
int int32 = Convert.ToInt32(_source.Substring(index * 2, 2), 16);
buffer[index] = (byte)int32;
}
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream((Stream)memoryStream, des.CreateDecryptor(), CryptoStreamMode.Write);
cryptoStream.Write(buffer, 0, buffer.Length);
cryptoStream.FlushFinalBlock();
str = Encoding.Default.GetString(memoryStream.ToArray());
memoryStream.Close();
}
catch
{
str = "Key Error...";
}
return str;
}
public void Main(string[] args)
{
string decrypted = this.DecryptStr(args[0], "0BDFC73BC56346AA");
Console.WriteLine(decrypted);
}
}
}
我不知道任何C#,但似乎語法確定從一個紅寶石點/ Python程序員。不幸的是,當我嘗試編譯它時,我得到以下錯誤:
------ Build started: Project: Decrypt, Configuration: Debug Any CPU ------
CSC : error CS5001: Program 'c:\Users\John\Documents\Visual Studio 2012\Projects\Decrypt\Decrypt\obj\Debug\Decrypt.exe' does not contain a static 'Main' method suitable for an entry point
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
線索是錯誤消息:「不包含** **靜態'Main'法」 –