
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
Found 2587 Articles for Csharp

9K+ Views
For anagram, another string would have the same characters present in the first string, but the order of characters can be different.Here, we are checking the following two strings −string str1 = "heater"; string str2 = "reheat";Convert both the strings into character array −char[] ch1 = str1.ToLower().ToCharArray(); char[] ch2 = str2.ToLower().ToCharArray();Now, sort them −Array.Sort(ch1); Array.Sort(ch2);After sorting, convert them to strings as shown in the following code −Example Live Demousing System; public class Demo { public static void Main () { string str1 = "heater"; string str2 = "reheat"; char[] ch1 ... Read More

4K+ Views
Abstract methods do not provide an implementation and they force the derived classes to override the method. It is declared under abstract class. An abstract method only has the method definitionVirtual methods have an implementation, unlike the Abstract method and it can exist in the abstract and non-abstract class. It provides the derived classes with the option of overriding it.Virtual FunctionsThe virtual keyword is useful in modifying a method, property, indexer, or event. When you have a function defined in a class that you want to be implemented in an inherited class(es), you use virtual functions. The virtual functions could ... Read More

4K+ Views
In C#, an array name and a pointer to a data type same as the array data, are not the same variable type. For example, int *p and int[] p, are not the same type. You can increment the pointer variable p because it is not fixed in memory but an array address is fixed in memory, and you can't increment that.Here is an example −Exampleusing System; namespace UnsafeCodeApplication { class TestPointer { public unsafe static void Main() { int[] list = {5, 25}; fixed(int *ptr = ... Read More

624 Views
DynamicStore any type of value in the dynamic data type variable created using dynamic keyword. Type checking for these types of variables takes place at run-time. Dynamic are dynamically typed variables.The following is the syntax for declaring a dynamic type −dynamic = value;The following is an example −dynamic val1 = 100; dynamic val2 = 5; dynamic val3 = 20;The dynamic types are similar to object types except that type checking for object type variables takes place at compile time, whereas that for the dynamic type variables takes place at runtime.VarThe "var" keyword initializes variables with var support. Just assign ... Read More

283 Views
Firstly, set an array with values −int[] myArr = new int[] { 34, 23, 77, 67 };To get the average, firstly get the sum of array elements.Divide the sum with the length of the array and that will give you the average of the elements −int sum = 0; int average = 0; for (int i = 0; i < len; i++) { sum += myArr[i]; } average = sum / len;The following is the complete code to get the array in C# −Example Live Demousing System; public class Program { public static void Main() ... Read More

3K+ Views
For compiling unsafe code, you have to specify the /unsafe command-line switch with command-line compiler. For example, to compile a program named one.cs containing unsafe code, from command line, give the command − csc /unsafe one.cs Under Visual Studio IDE, enable use of unsafe code in the project properties. The following are the steps − Open Project properties by double clicking the properties node in the Solution Explorer. Click on the “Build” tab. Select the option "Allow unsafe code".

578 Views
To search files from the list of files in a directory, try to run the following code −Exampleusing System; using System.IO; namespace Demo { class Program { static void Main(string[] args) { //creating a DirectoryInfo object DirectoryInfo mydir = new DirectoryInfo(@"d:\amit"); // getting the files in the directory, their names and size FileInfo [] f = mydir.GetFiles(); foreach (FileInfo file in f) { Console.WriteLine("File Name: {0} Size: ... Read More

402 Views
The .NET Framework 4 brought the System.Collections.Concurrent namespace. This has several collection classes that are thread-safe and scalable. These collections are called concurrent collections because they can be accessed by multiple threads at a time. The following concurrent collection types use lightweight synchronization mechanisms: SpinLock, SpinWait, etc. These are new in .NET Framework 4. Let us see the concurrent collection in C# − Type Description BlockingCollection Bounding and blocking functionality for any type. ConcurrentDictionary Thread-safe implementation of a dictionary of key-value pairs. ConcurrentQueue Thread-safe implementation of a FIFO (first-in, first-out) queue. ConcurrentStack Thread-safe ... Read More

4K+ Views
Unmanaged CodeApplications that are not under the control of the CLR are unmanagedThe unsafe code or the unmanaged code is a code block that uses a pointer variable.The unsafe modifier allows pointer usage in unmanaged code.Let us see the example −Examplestatic unsafe void Main(string[] args) { int var = 20; int* p = &var; Console.WriteLine("Data is: {0} ", var); Console.WriteLine("Address is: {0}", (int)p); Console.ReadKey(); }Managed CodeManaged code is a code whose execution is managed by Common Language Runtime. It gets the managed code and compiles it into machine code. After that, the code is executed.The ... Read More

4K+ Views
Commonly used wildcard characters are the asterisk (*). It represents zero or more characters in a string of characters.In the following example asterisk is used to match words that begins with m and ends with e −@”\bt\S*s\b”The following is the complete code −Example Live Demousing System; using System.Text.RegularExpressions; namespace Demo { public class Program { private static void showMatch(string text, string expr) { MatchCollection mc = Regex.Matches(text, expr); foreach (Match m in mc) { Console.WriteLine(m); } ... Read More