Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 3154 of 3363
628 Views
To calculate fractional power in C#, use the Math.Pow method.The following sets 5 to the power 3.7 −double res = Math.Pow(5, 3.7);The following is the complete example showing how to calculate fractional power in C# −Example Live Demousing System; class Program { static void Main() { double res = Math.Pow(5, 3.7); Console.WriteLine("Result = {0}", res); Console.ReadLine(); } }OutputResult = 385.646164200006
351 Views
To define a custom method in C#, use the following syntax − (Parameter List) { Method Body }To call a custom method, try to run the following code. It has the checkPalindrome() method which is called to checker whether the binary representation is Palindrome or not −Example Live Demousing System; public class Demo { public static long funcReverse(long num) { long myRev = 0; while (num > 0) { myRev = 1; } return myRev; } public static ... Read More
1K+ Views
To calculate power of a number using recursion, try the following code.Here, if the power is not equal to 0, then the function call occurs which is eventually recursion −if (p!=0) { return (n * power(n, p - 1)); }Above, n is the number itself and the power reduces on every iteration as shown below −Example Live Demousing System; using System.IO; public class Demo { public static void Main(string[] args) { int n = 5; int p = 2; long res; res = power(n, p); Console.WriteLine(res); } static long power (int n, int p) { if (p!=0) { return (n * power(n, p - 1)); } return 1; } }Output25
4K+ Views
To calculate the size of a folder in C#, use the Directory.EnumerateFiles Method and get the files.To get the sub- directories, use the EnumerateDirectories method. Our folder is set using DirectoryInfo class −DirectoryInfo info = new DirectoryInfo(@"D:/new");Now find the size −long totalSize = info.EnumerateFiles().Sum(file => file.Length); For the directories, use −info.EnumerateDirectories()Other manipulations you can perform on Directories in C# are:MethodDescriptionCreateDirectory(String)Creates all directories and subdirectories in the specified path unless they already exist.CreateDirectory (String, DirectorySecurity)Creates all the directories in the specified path, unless the already exist, applying the specified Windows security.Delete(String)Deletes an empty directory from a specified path.Delete(String, Boolean)Deletes the specified ... Read More
370 Views
A stream for file operations such as read and write is provided by the FileStream class.Create an object like thisFileStream fstream = new FileStream("d:ew.txt", FileMode.OpenOrCreate);Above we have used FileMode.OpenOrCreate so that the file or opened or created if it does not already exist.The following is n example showing how to use the FileStream class in C# −using System; using System.IO; public class Demo { public static void Main(string[] args) { FileStream fstream = new FileStream("d:ew.txt", FileMode.OpenOrCreate); // write into the file fstream.WriteByte(90); // close the file fstream.Close(); } }
5K+ Views
The following are the access specifiers supported by C#.NET −Public Access SpecifierIt allows a class to expose its member variables and member functions to other functions and objects.Private Access SpecifierPrivate access specifier allows a class to hide its member variables and member functions from other functions and objects. Only functions of the same class can access its private members.Protected Access SpecifierProtected access specifier allows a child class to access the member variables and member functions of its base class.Internal Access SpecifierInternal access specifier allows a class to expose its member variables and member functions to other functions and objects in ... Read More
210 Views
If you want to write binary information into the stream, then use the BinaryWriter class in C#. You can find it under the System.IO namespace.The following is the implementation of the BinaryWriter class −static void WriteMe() { using (BinaryWriter w = new BinaryWriter(File.Open("C:\abc.txt", FileMode.Create))) { w.Write(37.8); w.Write("test”); } } static void ReadMe() { using (BinaryReader r = new BinaryReader(File.Open("C:\abc.txt", FileMode.Open))) { Console.WriteLine("Value : " + r.ReadDouble()); Console.WriteLine("Value : " + r.ReadString()); } }Above, theBinaryWriter class opens a file and writes content into it ... Read More
127 Views
The Item property of the BitArray class gets or sets the value of the bit at a specific position in the BitArray.Use the keyword to define the indexers instead of implementing the Item property. To access an element, use the mycollection[index].The following is the implementation of BitArray class Item property −Example Live Demousing System; using System.Collections; class Demo { static void Main() { bool[] arr = new bool[5]; arr[0] = true; arr[1] = true; arr[2] = false; arr[3] = false; BitArray ... Read More
212 Views
Use the BinaryReader class if you want to read binary information from the stream.The BinaryReader class is in System.IO namespace.The following is an example showing using the BinaryReader class to read from a file −static void WriteMe() { using (BinaryWriter w = new BinaryWriter(File.Open("C:\abc.txt", FileMode.Create))) { w.Write(25.9); w.Write("DEMO DATA"); } } static void ReadMe() { using (BinaryReader r = new BinaryReader(File.Open("C:\abc.txt", FileMode.Open))) { Console.WriteLine("Value : " + r.ReadDouble()); Console.WriteLine("Value : " + r.ReadString()); } }The above method is called in the Main() method ... Read More
2K+ Views
The conditional statement requires the programmer to specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.The following are the types of conditional statements −Sr.NoStatement & Description1if statementAn if statement consists of a boolean expression followed by one or more statements.2if...else statementAn if statement can be followed by an optional else statement, which executes when the boolean expression is false.3nested if statementsYou can use one ... Read More