Consider a Scenario:
You are working on the .NET Project. In that case, your manager asked you whether you are working on a 32-bit or a 64-bit operating system. Then, you checked the system hardware and said it is a 64 bit operating system.
But he replied: Being a .NET Programmer, you should know the operating system property using the Predefined Properties through C# rather than checking manually.
So, the manager told you that there is a method in C# to check the current working operating system.
Now, we will see about that property.
Environment.Is64BitOperatingSystem Property
This property is available in the Environment Class. It provides an information about the working environment like variables, methods used and system related information in C#.
The Is64BitOperatingSystem is a property in C# Environment class that is used to check the current operating system. If the operating system is a 64-bit architecture, it returns True. Otherwise, it returns False.
This property can be applied in .NET 2.0,2.1,3.0.3.1 and 6.7.
Syntax:
Let’s see the following examples to understand the concept much better.
Example 1:
Check your OS architecture using the previous property.
Explanation:
Line 01: We use the System library for using the Console.WriteLine() and the other statements in our code.
Line 03: We create a class named Linuxhint after.
Line 05: The main() method starts from here.
Line 08: Console.WriteLine(Environment.Is64BitOperatingSystem);
Inside the main() method, we check the Operating System Architecture using the Is64BitOperatingSystem property.
Finally, the output is True which means that we are currently running our C# program on a 64-bit operating system.
Example 2:
We can make the previous code in a more precise way. Just add the conditional statements to display the output with a message.
Explanation:
Line 01: We use the System library for using the Console.WriteLine() and the other statements in our code.
Line 03: We create a class named Linuxhint after.
Line 05: The main() method starts from here.
Line 08: if(Environment.Is64BitOperatingSystem==true)
Inside the main() method, we check if the Operating System is 64-bit Architecture using the Is64BitOperatingSystem property inside the “if” condition.
If this becomes true, the following message will be displayed by executing the Console statement:
Line 14: Otherwise, it goes to the else block and executes the Console statement at Line 17.
Line 17: Console.WriteLine(“You are not working on 64-bit OS Architecture”);
Finally, the output is You are working on 64-bit OS Architecture which means that we are currently running our C# program on a 64-bit operating system (If block is executed).
Conclusion
Now, the programmer has the property that checks the operating system architecture in which his programs are running. He told his manager that this property is available in the Environment Class which is used to check if the current operating system is 64-bit or not by returning a Boolean value. If the operating system is 64-bit Architecture, it returns True. Otherwise, it returns False. The manager felt happy.
from https://ift.tt/2Kr0Zd8
0 Comments