- Home /
Class, struct, or interface method must have a return type
I'm trying to convert the commented JS to C#. It's stalling on the "public static Md5Sum(string strToEncrypt)" line with this error:
error CS1520: Class, struct, or interface method must have a return type
// function doLogin() {
// var sHash = Md5Sum(strUsername+strPassword+sYourID);
// var tURL = sURL;
// tURL=tURL+"?mdwCMD=loginRequest";
// tURL=tURL+"&user="+strUsername;
// tURL=tURL+"&pass="+strPassword;
// tURL=tURL+"&md5="+sHash;
// var rLogin = WWW(tURL);
// yield rLogin;
// switch(rLogin.text) {
// case "loginTrue":
// // GUI OR REDIRECT
// Application.ExternalEval("document.location.replace('"+sMemArea+"')");
// break;
// case "loginFalse":
// sLoginStatus = "Login Status: Failed, Please Try Again";
// yield WaitForSeconds(3);
// sLoginStatus = "";
// break;
// };
//}
IEnumerator doLogin()
{
string sHash = Md5Sum(strUsername+strPassword+yourID);
string tURL = phpURL;
tURL = tURL+"?mdwCMD=loginRequest";
tURL = tURL+"&user="+strUsername;
tURL = tURL+"&pass="+strPassword;
tURL = tURL+"&md5="+sHash;
WWW rLogin = WWW(tURL);
yield return rLogin;
switch(rLogin.text)
{
case "loginTrue":
//GUI or redirect
Application.ExternalEval("document.location.replace('"+sMemArea+"')");
break;
case "loginFalse":
sLoginStatus = "Login Status: FAILED, please try again";
yield return new WaitForSeconds(3);
sLoginStatus = "";
break;
}
}
//============================================
// static function Md5Sum(strToEncrypt: String) {
// var encoding = System.Text.UTF8Encoding();
// var bytes = encoding.GetBytes(strToEncrypt);
// var md5 = System.Security.Cryptography.MD5CryptoServiceProvider(); //-Encrypt bytes
// var hashBytes:byte[] = md5.ComputeHash(bytes); //-Convert the encrypted bytes back to a string (base 16)
// var hashString = "";
// for (var i=0; i<hashBytes.Length; i++) {
// hashString += System.Convert.ToString(hashBytes[i],16).PadLeft(2,"0"[0]);
// } return hashString.PadLeft(32,"0"[0]);
// }
public static Md5Sum(string strToEncrypt)
{
var encoding = System.Text.UTF8Encoding();
var bytes = encoding.GetBytes(strToEncrypt);
var md5 = System.Security.Cryptography.MD5CryptoServiceProvider(); // Encrypt bytes
byte[] hashbytes = md5.ComputeHash(bytes); // Convert encrypted bytes back to string (base 16)
string hashString = "";
for (int i = 0; i < hashbytes.Length; i++)
{
hashString += System.Convert.ToString(hashbytes[i],16).PadLeft(2,"0"[0]);
}
return hashString.PadLeft(32,"0"[0]);
}
Comment
Best Answer
Answer by Peter G · Sep 03, 2011 at 07:43 PM
It means exactly what it says. In C#, you have to state the return type of a function. Here's the basic template for a method:
accessModifier ReturnType FunctionName (ParameterType args[]) {
You need to put in a return type. If you don't return an object, put in void
Your answer

Follow this Question
Related Questions
Return a custom class from function 1 Answer
type function not returning. c# 2 Answers
Turn Strings[] into vars[]? 1 Answer
how to typecast a method holder in Javascript, like Delegate 1 Answer
What is the type of my prefab? 2 Answers