Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello, friends

I have this code in VB.NET:


VB.NET
Public Class MyClass
	Public Sub MyFunction()
		Dim c As System.Drawing.Color
		c = Color.Red
		c = c AND &hFFFFFFFF
	End Sub
End Class


This code is to add Color to c variable, how can I convert this to C# or JAVA Code?
I've tried this:
C#
Color c = Color.Red;
        c = c & 0xFFFFFFFF;

but it did not worked!!
Posted
Comments
Richard Deeming 3-Dec-15 10:14am    
That VB.NET code will not compile:
BC30452 Operator 'And' is not defined for types 'Color' and 'Integer'.

Explain what you're trying to do.

1 solution

I cannot see what the line
VB
c = c AND &hFFFFFFFF

is doing. .NET Color structure does not have bitwise operators defined.
Moreover, taking an int value and making a bitwise-AND between it and -1 basically returns the same int value.

My feeling is that this code is already copied from a java-one by someone who is not understanding what it is doing. This code does not add anything to color; it tries to make a bitwise operation that leaves the result unchanged.

You may have to define precisely what you are expecting from this statement.

Regards.

[Edit] Corrected a minor imprecision regarding the bitwise-AND stuff.
 
Share this answer
 
v2
Comments
Suvendu Shekhar Giri 3-Dec-15 13:07pm    
Hi Phil,

Had overlooked the code shared by OP and was wrong in the approach. I thought it's all about just converting the code from VB.Net to C#. But I was wrong.

Thanks for pointing out the mistake. Appreciate that.

Regarding your answer to the question, it deserves my 5 !
phil.o 3-Dec-15 14:28pm    
Thank you, you're welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900