- 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
2K+ Views
Exception handling is based on the following keywords and its usage −try − A try block identifies a block of code for which particular exceptions is activated. It is followed by one or more catch blocks.catch − A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception.finally − The finally block is used to execute a given set of statements, whether an exception is thrown or not thrown. For example, if you open a file, it must be closed ... Read More
735 Views
On Windows, the best IDE to run C# programs is Visual Studio. On MacOS, the best IDE can be considered as Monodevelop.Monodevelop is an open source IDE that allows you to run C# on multiple platforms i.e. Windows, Linux and MacOS. Monodevelop is also known as Xamarin Studio.Monodevelop has a C# compiler to run C# programs. It can be used on Windows, macOS and Linux.For Mac, a special version of MonoDevelop was introduced and it was called Visual Studio for Mac. It has many of the features of what the same IDE provides for Windows like tool for and IntelliSense ... Read More
588 Views
To reduce concurrency issues in C#, use the volatile keyword. Let us seen an example.The following is how you use a volatile keyword for public variable −class Program { public volatile int a; public void Program(int _a) { i = _i; } }Let us see another example: We have two static variables. Set them in a new method −_out = "Welcome!"; _new = true;We declared them as static before using volatile −static string _out; static volatile bool new;Now you need to run the method on a thread −new Thread(new ThreadStart(volatileFunc)).Start();Read the value of the ... Read More
5K+ Views
The stream is basically the sequence of bytes passing through the communication path. There are two main streams: the input stream and the output stream. The input stream is used for reading data from file (read operation) and the output stream is used for writing into the file (write operation).The FileStream class in the System.IO namespace helps in reading from, writing to and closing files. This class derives from the abstract class Stream.Create a FileStream object to create a new file or open an existing file. The following is the syntax −FileStream = new FileStream( , , , );Here, ... Read More
465 Views
Substring is used to get the sub-parts of a string in C#. We have the substring() method for this purpose. Use the substring() method in C# to check each and every substring for unique characters. Loop it until the length of the string.If anyone the substring matches another, then it would mean that the string does not have unique characters.You can try to run the following code to determine if a string has all unique characters. The example shows the usage of Substring() method −Exampleusing System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public class Demo { ... Read More
6K+ Views
C# exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero.C# exception handling is performed using the following keywords −try − A try block identifies a block of code for which particular exceptions is activated. It is followed by one or more catch blocks.catch − A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception.finally − The finally block is used to execute a given set ... Read More
1K+ Views
The System.SystemException class is the base class for all predefined system exception. Some of the exception classes derived from the System.Exception class are the System.ApplicationException and System.SystemException classes.The System.ApplicationException class supports exceptions generated by application programs. Hence the exceptions defined by the programmers should derive from this class.The following are the exceptions under the base class System.SystemException −Sr.No.Exception Class & Description1System.IO.IOExceptionHandles I/O errors.2System.IndexOutOfRangeExceptionHandles errors generated when a method refers to an array index out of range.3System.ArrayTypeMismatchExceptionHandles errors generated when type is mismatched with the array type.4System.NullReferenceExceptionHandles errors generated from referencing a null object.5System.DivideByZeroExceptionHandles errors generated from dividing a dividend with zero.6System.InvalidCastExceptionHandles errors ... Read More
1K+ Views
The reference data type in C# does not have the actual data stored in a variable, but they contain a reference to the variables.In C#, the following are the built-in reference types −Object TypeThe Object Type is the ultimate base class for all data types in C# Common Type System (CTS). The object types can be assigned values of any other types, value types, reference types, predefined or user-defined types.Exampleobject ob; ob = 250; // boxingDynamic TypeStore any type of value in the dynamic data type variable. Type checking for these types of variables takes place at run-time.Exampledynamic d = ... Read More
668 Views
Finalizers in C# are used to destruct instances of classes. With that, you can also use it to release resources.Here are some of the key points about Finalizers −Only one finalizer is allowed for a classYou cannot inherit or overload FinalizersA finalizer cannot have parametersFinalizers invoke automaticallyFinalizers in C# are declared like destructors. Let’s say the class name is Demo, therefore, the following would be our finalizer −~Demo() { // }The finalizer declaration is prefixed with a tilde before the class name.
476 Views
The NameValueCollection sets more than one value for a single key. Now let us see how to use them in our C# program.Set the collection −static NameValueCollection GetCollection() { NameValueCollection myCollection = new NameValueCollection(); myCollection.Add("Tim", "One"); myCollection.Add("John", "Two"); myCollection.Add("Jamie", "Three"); return myCollection; }Now with the GetCollection() method use the “AllKeys” method property to display all the keys −NameValueCollection myCollection = GetCollection(); foreach (string key in myCollection.AllKeys) { Console.WriteLine(key); }