Calling a class


May 12, 2016
Programming Experience
In this code I am trying to call PW_InFile = Encryption.DencryptString(PW_InFile, strengthLength);
but it does not work. I can't check if the code in public static DencryptString(string PW_InFile, int stringLength) works.

The button13_Click procedure works up until the class call. If I hover over the call it says "Cannot implicitly convert 'void' to a string

Can you help me?
        private void button13_Click(object sender, EventArgs e)
            string line;
            string PW_InFile = "";
            // Read the file
            string path = Directory.GetCurrentDirectory();
            System.IO.StreamReader file = new System.IO.StreamReader(path + "\\MyDataPW.txt");
            while ((line = file.ReadLine()) != null)
                PW_InFile = line;
            //LETS DE-ENCRYPT IT
            int strengthLength = PW_InFile.Length;
            PW_InFile = Encryption.DencryptString(PW_InFile, strengthLength);

namespace MyData
    public class Encryption
        public static DencryptString(string PW_InFile, int stringLength)
            String STEMP = "";
            for (int i = 0; i < stringLength; i = i + 3)
                STEMP = PW_InFile.Substring( i, 3) - 103;

            return PW_InFile = STEMP;//RETURN THE DECRYPTED STRING


Last edited by a moderator:
That DencryptString does make sense for a number of reasons. Firstly, there's no such word a "dencrypt". So presumably the method should be named DecryptString. Secondly, if it's supposed to return a String then declare it as doing so, i.e. specify the return type in the declaration. Thirdly, if you want to return a String then just return it. What point is there to assigning it to a parameter passed by value? Finally, the code in the loop is not going to do what you want. You're overwriting the value of STEMP in every iteration, so anything that came before will be lost.
"Dencrypt", I don't think that would stop the call.
"specify the return type in the declaration" can you give me an example?
The third and forth points, while not what I want, should not have stopped the call, they would just give me the wrong answers, I will fix that.
Top Bottom