So when I do thhe C# like how fix? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

So when I do thhe C# like how fix?

public static bool CompareBooleans(bool orig, bool val) return AreBooleansEqual(orig, val); internal static bool AreBooleansEqual(bool orig, bool val) if(orig == val) return false; return true; Here’s my C# code. Pls someone help idk what im doin 😭😭😭

18th Jun 2024, 3:10 AM
BlueZ
BlueZ - avatar
4 Respuestas
+ 2
I… nevermind. Just use this and tell me how that works. using System; using System.Runtime.CompilerServices; public class MyClass { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool CompareBooleans(bool orig, bool val) { return orig == val; } } public class Program { public static void Main(string[] args) { bool result = MyClass.CompareBooleans(true, false); Console.WriteLine("Comparison result: " + result); } } Good luck on your journey! )))
18th Jun 2024, 3:24 AM
X—X
X—X - avatar
+ 1
Alright so you’re comparing two boolean values ‘orig’ and ‘val.’ And it returns ‘true’ if they are equal, and ‘false’ otherwise. But you definitely need to heavily optimize this and you’re clearly aware of this which makes sense since you used the “optimize” tag. Here’s how I would solve this problem. // Method declaration with an attribute for aggressive inlining (if you want to micro-optimize this & it’s frequently called, otherwise remove this) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool CompareBooleans(bool orig, bool val) { // Compare two boolean values and return true if they are equal, false otherwise return orig == val; } Added a micro-optimization in as well for fun, but feel free to remove it if it’s unneeded/unwanted. Good luck on your coding journey! )))
18th Jun 2024, 3:18 AM
X—X
X—X - avatar
+ 1
Im getting errors. Like run ur code bro in sololearn c# and u get errors u sure u know the answer? :-) respectuflly lol
18th Jun 2024, 3:23 AM
BlueZ
BlueZ - avatar
+ 1
Yay it worked! It said”Comparison ruslt false!” Thank you!! 😍👍 ur very smart and fast anwer
18th Jun 2024, 3:27 AM
BlueZ
BlueZ - avatar