Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 862 of 2547
How to open hidden file using C#?
To open a hidden file in C#, you need to first make it visible by removing the hidden attribute, then read its contents, and optionally restore the hidden attribute afterward. Hidden files have the FileAttributes.Hidden attribute set, which prevents them from being displayed in normal file explorers. Syntax Following is the syntax for removing the hidden attribute from a file − FileInfo file = new FileInfo(filePath); file.Attributes &= ~FileAttributes.Hidden; Following is the syntax for restoring the hidden attribute − file.Attributes |= FileAttributes.Hidden; Using FileInfo to Remove Hidden Attribute The ...
Read MoreHow to convert Trigonometric Angles in Radians using C#?
To convert trigonometric angles from degrees to radians in C#, multiply the degree value by Math.PI/180. Most trigonometric functions in C# expect angles in radians, so this conversion is essential for accurate calculations. Syntax Following is the syntax for converting degrees to radians − double radians = degrees * (Math.PI / 180.0); Following is the syntax for converting radians to degrees − double degrees = radians * (180.0 / Math.PI); Converting Degrees to Radians Example The following example shows how to properly convert degrees to radians before using ...
Read MoreQuickly convert Decimal to other bases in C#
Converting decimal numbers to other bases in C# can be efficiently accomplished using a Stack data structure. The stack naturally handles the reversal of digits that occurs during the conversion process, making it an ideal choice for base conversion algorithms. How It Works The conversion process involves repeatedly dividing the decimal number by the target base and storing the remainders. Since division produces digits in reverse order, a stack helps retrieve them in the correct sequence: Divide the decimal number by the target base Push the remainder onto the stack Update the number to the quotient ...
Read MoreWhat is the C# equivalent for the Java System.exit(0)?
The C# equivalent for Java's System.exit(0) is the Environment.Exit() method. This method terminates the current process and returns an exit code to the operating system, just like its Java counterpart. Syntax Following is the syntax for using Environment.Exit() − Environment.Exit(exitCode); Parameters exitCode − An integer value returned to the operating system. Use 0 to indicate successful termination, and non-zero values to indicate different error conditions. Exit Code Conventions Exit Code Meaning 0 Process completed successfully 1 General error ...
Read MoreDirectoryNotFoundException in C#
The DirectoryNotFoundException in C# is thrown when an application attempts to access a directory that does not exist on the file system. This exception is part of the System.IO namespace and commonly occurs during file and directory operations. Syntax The exception is automatically thrown by the .NET framework when directory operations fail − public class DirectoryNotFoundException : SystemException Common methods that can throw this exception include − Directory.GetDirectories(path); Directory.GetFiles(path); DirectoryInfo directoryInfo = new DirectoryInfo(path); When DirectoryNotFoundException Occurs Here is an example that demonstrates when this exception occurs by trying ...
Read MoreComplex Numbers in C#
A complex number in C# consists of two components: a real part and an imaginary part. For example, in the complex number 7+5i, the real part is 7 and the imaginary part is 5 (the coefficient of i). C# allows you to create custom data structures to represent complex numbers using struct and implement mathematical operations using operator overloading. Syntax Following is the syntax for creating a complex number structure − public struct Complex { public double real; public double imaginary; public ...
Read MoreWhat is the C# equivalent of C++ friend keyword?
In C++, the friend keyword allows external functions or classes to access private and protected members of a class. C# does not have a direct equivalent to the friend keyword, but there are several approaches to achieve similar functionality. Understanding the friend Concept A friend function in C++ is defined outside a class but has access to all private and protected members of that class. While C# doesn't support this directly, it provides alternative mechanisms to control access between closely related classes. Using Nested Classes The closest equivalent to C++ friend functionality is using nested classes. ...
Read MoreCompilation and Execution of a C# Program
To compile and execute a program in C#, you can use several methods depending on your development environment. The most common approaches include using Visual Studio IDE, command-line tools, or online compilers. Using Visual Studio IDE In Microsoft Visual Studio IDE, compilation and execution is straightforward − Click the Run button or press F5 key to build and execute the project. Visual Studio automatically compiles your code and runs the executable. Any compilation errors will appear in the Error List window. Command-Line Compilation You can compile C# programs using the command-line C# compiler ...
Read MoreC# program to print all the numbers divisible by 3 and 5 for a given number
To print numbers divisible by both 3 and 5, we use the modulus operator % with the logical AND operator &&. A number is divisible by both 3 and 5 if the remainder is zero when divided by each of these numbers. Syntax Following is the syntax to check if a number is divisible by both 3 and 5 − if (num % 3 == 0 && num % 5 == 0) { // number is divisible by both 3 and 5 } Alternatively, since a number divisible by both 3 ...
Read MoreHow to convert a JavaScript array to C# array?
Converting a JavaScript array to a C# array involves passing the JavaScript array data to your C# application, typically through web forms, AJAX requests, or by converting the array to a string format that C# can parse. The most common approach is to serialize the JavaScript array to a string (usually comma-separated or JSON format) and then parse it in C# to recreate the array. Using Comma-Separated String Conversion First, convert the JavaScript array to a comma-separated string using the join() method − var myArr = ["Welcome", "to", "the", "Web", "World"]; ...
Read More