It goes against the spirit of the assignment, but I'd do it for kicks...
Create your own class, overload the + operator to do multiplication.
Create your homework project; add your first project as a reference. Write your code to be
return new SuperInt(x) + SuperInt(y);
Everyone else is going to some variation of shifting bits or addition. Half of the kids are going to post the exact code returned by a Google search anyway. At least this way, you'll be unique.
The assignment itself is really just an exercise in lateral thinking. Any sane person would use the * operator when working in .Net.
EDIT: If you really want to be a class clown - overload the * operator and implement it with bitwise operations and addition.
Additional Answer #1 (if you are willing to change your method signature...)
What about this?
static void Main(string[] args)
{
Console.WriteLine(string.Format("{0} * {1} = {2}", 5, 6, MultiplyNumbers(5, 6)));
Console.WriteLine(string.Format("{0} * {1} = {2}", -5, 6, MultiplyNumbers(-5, 6)));
Console.WriteLine(string.Format("{0} * {1} = {2}", -5, -6, MultiplyNumbers(-5, -6)));
Console.WriteLine(string.Format("{0} * {1} = {2}", 5, 1, MultiplyNumbers(5, 1)));
Console.Read();
}
static double MultiplyNumbers(double x, double y)
{
return x / (1 / y);
}
Outputs:
5 * 6 = 30
-5 * 6 = -30
-5 * -6 = 30
5 * 1 = 5
One straight-forward line of code.
But still, if you take this approach, be prepared to argue a bit. It does multiply integers; by implicitly converting them to doubles in the call. Your question didn't say you could use only integers, just that it had to multiply two integers without using '*'.
EDIT: Since you say you can't change the signature of MultiplyNumbers - you can accomplish it without doing that:
static uint MultiplyNumbers(uint x, uint y)
{
return MultiplyDouble(x, y);
}
static uint MultiplyDouble(double x, double y)
{
return Convert.ToUInt32(x / (1 / y));
}
Additional Answer #2
This is my favorite approach yet.
Take the values, send them to Google, parse the result.
static uint MultiplyNumbers(uint x, uint y)
{
System.Net.WebClient myClient = new System.Net.WebClient();
string sData = myClient.DownloadString(string.Format("http://www.google.com/search?q={0}*{1}&btnG=Search",x,y));
string ans = x.ToString() + " * " + y.ToString() + " = ";
int iBegin = sData.IndexOf(ans,50) + ans.Length ;
int iEnd = sData.IndexOf('<',iBegin);
return Convert.ToUInt32(sData.Substring(iBegin, iEnd - iBegin).Trim());
}