- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2628 Articles for Csharp
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
345 Views
A static constructor is a constructor declared using a static modifier. It is the first block of code executed in a class. With that, a static constructor executes only once in the life cycle of class.The following is an example of static constructors in C# −Exampleusing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Difference { class Demo { static int val1; int val2; static Demo() { Console.WriteLine("This is Static Constructor"); val1 = 70; } ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
427 Views
The C# static class cannot be instantiated and can only have only static members. The static class in C# is sealed and cannot contain instance constructors.The following is an example with static class and static members −Exampleusing System; public static class Demo { public static float PI = 3.14f; public static int calc(int n){return n*n;} } class Program { public static void Main(string[] args) { Console.WriteLine("PI: "+Demo.PI); Console.WriteLine("Square: " + Demo.calc(3)); } }Above, the static class is −public static class Demo { public static float PI ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
569 Views
Sealed class in C# with the sealed keyword cannot be inherited. In the same way, the sealed keyword can be added to the method.When you use sealed modifiers in C# on a method, then the method loses its capabilities of overriding. The sealed method should be part of a derived class and the method must be an overridden method.Let us see an example of sealed class in C# −Exampleusing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo { class Program { static void Main(string[] args) { Result ob = new ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
241 Views
Recursive method call in C# is called Recursion. Let us see an example to calculate power of a number using recursion.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 −Exampleusing System; using System.IO; public class Demo { public static void Main(string[] args) { int n = 5; int p = 2; long res; ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
955 Views
Declare the reference parameters using the ref keyword. A reference parameter is a reference to a memory location of a variable. When you pass parameters by reference, unlike value parameters, a new storage location is not created for these parameters.Declare a ref parameter −public void swap(ref int x, ref int y) {}Declare a ref parameter of array type −static void Display(ref int[] myArr)The following is an example showing how to work with ref parameter of an array type in C# −class TestRef { static void Display(ref int[] myArr) { if (myArr == null) { ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
4K+ Views
An exception is a problem that arises during the execution of a program. A C# exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero.Define your own exception. User-defined exception classes are derived from the Exception class.The following is an example −Exampleusing System; namespace UserDefinedException { class TestFitness { static void Main(string[] args) { Fitness f = new Fitness(); try { f.showResult(); } catch(FitnessTestFailedException ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
3K+ Views
Copy Constructor creates an object by copying variables from another object.Let us see an example −Exampleusing System; namespace Demo { class Student { private string name; private int rank; public Student(Student s) { name = s.name; rank = s.rank; } public Student(string name, int rank) { this.name = name; this.rank = rank; } public string Display { ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
The System.Math class in C# provides methods are properties to perform mathematical operations, trigonometric, logarithmic calculations, etc.Some of its methods include −Sr.NoMethod & Description1Abs(Decimal)Returns the absolute value of a Decimal number.2Abs(Double)Returns the absolute value of a double-precision floating-point number.3Abs(Int16)Returns the absolute value of a 16-bit signed integer.4Abs(Int32)Returns the absolute value of a 32-bit signed integer.5Abs(Int64)Returns the absolute value of a 64-bit signed integer.6Abs(SByte)Returns the absolute value of an 8-bit signed integer.7Abs(Single)Returns the absolute value of a single-precision floating-point number.8Acos(Double)Returns the angle whose cosine is the specified number.9Asin(Double)Returns the angle whose sine is the specified number.10Atan(Double)Returns the angle whose tangent is ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
1K+ Views
The following are the logical operators that you can use on Strings in C#.OperatorDescriptionExample&&Called Logical AND operator. If both the operands are non zero then condition becomes true.(A && B) is false.||Called Logical OR Operator. If any of the two operands is non zero then condition becomes true.(A || B) is true.!Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.!(A && B) is true.Let us see an example showing how to use logical AND operator on strings −Example Live Demousing System; using System.Collections.Generic; using System.Linq; ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
335 Views
The Directory class in C# has many methods to perform operations on directories and sub-directories −Sr.NoMethod & Description1CreateDirectory(String)Creates all directories and subdirectories in the specified path unless they already exist.2CreateDirectoryDirectorySecurity(String)Creates all the directories in the specified path, unless the already exist, applying the specified Windows security.3Delete(String)Deletes an empty directory from a specified path.4DeleteBoolean(String)Deletes the specified directory and, if indicated, any subdirectories and files in the directory.5EnumerateDirectories(String)Returns an enumerable collection of directory names in a specified path.6EnumerateDirectories(String, String)Returns an enumerable collection of directory names that match a search pattern in a specified path.To get the directory names, use the EnumerateDirectories method. ... Read More