C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-05-2009, 08:47 PM   #1
Registered User
 
Join Date: Nov 2009
Posts: 10
best Overloaded match for method ...

When I compile it tells me best overloaded match for method AESEncryption.shiftrow(byte[], byte);

I am still new to C sharp so can somebody tell me?

Code:
    public static void shiftRow(byte[] state, byte nbr)
    {
        int i;
        int j;
        byte tmp;
        // each iteration shifts the row to the left by 1 
        for (i = 0; i < nbr; i++)
        {
            tmp = state[0];
            for (j = 0; j < 3; j++)
                state[j] = state[j + 1];
            state[3] = tmp;
        }
    }
Code 2
Code:
 public static void shiftRows(ref byte state)
    {
        int i;
        // iterate over the 4 rows and call shiftRow() with that row 
        for (i = 0; i < 4; i++)
            shiftRow(Convert.ToInt16(state + i * 4), i);
    }
I need help with code 2
deathkosui is offline   Reply With Quote
Old 11-05-2009, 10:34 PM   #2
eh ya hoser, got a beer?
 
stumon's Avatar
 
Join Date: Feb 2003
Posts: 287
You're trying to pass variables with int class data types to a Method that takes an array of bytes as the first argument and a byte data type for the second argument. You need to figure out what you want to use, bytes or ints. Then make sure you want to send an array of them or just 1 element when you call the Method.

Code:
shiftRow(Convert.ToInt16(state + i * 4), i);
// Why have the Convert.ToInt16??? You're changing its data type, and 'i' is an integer to begin with.
__________________
The keyboard is the standard device used to cause computer errors!

Last edited by stumon; 11-05-2009 at 10:37 PM.
stumon is offline   Reply With Quote
Old 11-05-2009, 10:39 PM   #3
Registered User
 
Join Date: Nov 2009
Posts: 10
well i tried doing it with nothing and it still doesn't work
deathkosui is offline   Reply With Quote
Old 11-05-2009, 10:43 PM   #4
eh ya hoser, got a beer?
 
stumon's Avatar
 
Join Date: Feb 2003
Posts: 287
Quote:
Originally Posted by deathkosui View Post
well i tried doing it with nothing and it still doesn't work

You tried calling the Method without any arguments? Well that obviously wouldn't work unless you overloaded the Method with one that has no arguments. You just need to make sure that the Method gets the data types it wants, and the same number of them. Figure out what you want to pass. If its just 1 element of an array, then make the Method take 1 byte data type variable, otherwise, you will need to pass the whole array to that method if it asks for an array of bytes.
__________________
The keyboard is the standard device used to cause computer errors!
stumon is offline   Reply With Quote
Old 11-05-2009, 10:47 PM   #5
Registered User
 
Join Date: Nov 2009
Posts: 10
yeah but how do i pass a byte array through a method ?
deathkosui is offline   Reply With Quote
Old 11-05-2009, 10:53 PM   #6
eh ya hoser, got a beer?
 
stumon's Avatar
 
Join Date: Feb 2003
Posts: 287
Quote:
Originally Posted by deathkosui View Post
yeah but how do i pass a byte array through a method ?

Code:
public void MyMethod(byte[] hey)
{

// use hey[1] or hey[whatever] for something....

}


public void MyMethod2()
{
       byte[] blah = new byte[10];
       MyMethod(blah);
}
__________________
The keyboard is the standard device used to cause computer errors!
stumon is offline   Reply With Quote
Old 11-05-2009, 10:57 PM   #7
Registered User
 
Join Date: Nov 2009
Posts: 10
yeah okay that gives rid of the error but i want blah to stand for a value (state+4*i) is it possible

to put
int k = state+4*1;
byte[] blah = { k };
and add shiftRow(blah[1], i);
?
deathkosui is offline   Reply With Quote
Old 11-05-2009, 11:18 PM   #8
eh ya hoser, got a beer?
 
stumon's Avatar
 
Join Date: Feb 2003
Posts: 287
That all depends on what data type state is. In both examples of your code, you are passing something into either an array of byte's called state or in the second example its just a single byte variable called state. Somewhere you are going to have to cast something to make the data types match... and casting the name of an array will give you a runtime error.
__________________
The keyboard is the standard device used to cause computer errors!
stumon is offline   Reply With Quote
Old 11-05-2009, 11:23 PM   #9
Registered User
 
Join Date: Nov 2009
Posts: 10
oh i get it alright thanks for the help
deathkosui is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
No Match For Operator+ ??????? Paul22000 C++ Programming 24 05-14-2008 10:53 AM
We Got _DEBUG Errors Tonto Windows Programming 5 12-22-2006 05:45 PM
overloaded >> operator issue... soulredemption C++ Programming 2 10-17-2005 10:53 PM
2 array match ajastru2000 C++ Programming 5 07-18-2003 07:58 AM
overloaded on overloads emceedee C++ Programming 1 03-31-2003 02:14 AM


All times are GMT -6. The time now is 11:24 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22