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 3150 of 3363
1K+ Views
Using generic delegates, you do not need to define the delegate statement. They are defined in the System namespace.You can define a generic delegate with type parameters. For example −delegate T myDelegete(T n);ExampleThe following is an example showing how to create generic delegates in C# −using System; using System.Collections.Generic; delegate T myDelegete(T n); namespace GenericDelegateAppl { class TestDelegate { static int num = 5; public static int AddNum(int p) { num += p; return num; } ... Read More
765 Views
Generic collections in C# include , , etc.ListList is a generic collection and the ArrayList is a non-generic collection.Let us see an example. Here, we have six elements in the list −Example Live Demousing System; using System.Collections.Generic; class Program { static void Main() { // Initializing collections List myList = new List() { "one", "two", "three", "four", "five", "six" }; Console.WriteLine(myList.Count); ... Read More
1K+ Views
Firstly, let us create a dictionary −var d = new Dictionary(5);Now add the key and value −// add key and value d.Add("car", 25); d.Add("bus", 28); d.Add("motorbike", 17);Use orderby to order by values −var val = from ele in d orderby ele.Value ascending select ele;We have set ascending above to sort the dictionary in ascending order. You can also use descending.Display the values in ascending order −foreach (KeyValuePair ele in val) { Console.WriteLine("{0} = {1}", ele.Key, ele.Value); }
956 Views
The System.IO namespace has various classes useful for performing various operations with files, such as creating and deleting files, reading from or writing to a file, closing a file etc.The following are the I/O classes in C# −Sr.No.I/O Class & Description1BinaryReaderReads primitive data from a binary stream.2BinaryWriterWrites primitive data in binary format.3BufferedStreamA temporary storage for a stream of bytes.4DirectoryHelps in manipulating a directory structure.5DirectoryInfoUsed for performing operations on directories.6DriveInfoProvides information for the drives.7FileHelps in manipulating files.8FileInfoUsed for performing operations on files.9FileStreamUsed to read from and write to any location in a file.10MemoryStreamUsed for random access to streamed data stored in ... Read More
1K+ Views
A floating-point literal has an integer part, a decimal point, a fractional part, and an exponent part. You can represent floating point literals either in decimal form or exponential form.The following are some of the examples of floating point literals −9.23456 269485E-5FLet us now print the floating point literals −Example Live Demousing System; namespace Demo { class Program { static void Main(string[] args) { // float float a = 3.56f; Console.WriteLine(a); // float float b = 3.14159f; Console.WriteLine(b); } } }Output3.56 3.14159
426 Views
String literals or constants are enclosed in double quotes "" or with @"". A string contains characters that are similar to character literals: plain characters, escape sequences, and universal characters.Here are some examples of String Literals −“Hi, User" "You’re Welcome, \The following is an example showing the usage of string literals −Example Live Demousing System; namespace Demo { class Program { static void Main(string[] args) { // string string str1 ="Hello, World"; Console.WriteLine(str1); // Multi-line string string str2 = @"Welcome, Hope you are doing great!"; Console.WriteLine(str2); } } }OutputHello, World Welcome, Hope you are doing great!
5K+ Views
The using statement is used to set one or more than one resource. These resources are executed and the resource is released. The statement is also used with database operations.The main goal is to manage resources and release all the resources automatically.Let us see an example wherein “A” would print first since the SystemResource is allocated first.Example Live Demousing System; using System.Text; class Demo { static void Main() { using (SystemResource res = new SystemResource()) { Console.WriteLine("A"); } Console.WriteLine("B"); } } class SystemResource : IDisposable { public void Dispose() { Console.WriteLine("C"); } }OutputA C B
4K+ Views
Circular reference occurs when two or more interdependent resources cause lock condition. This makes the resource unusable.To handle the problem of circular references in C#, you should use garbage collection. It detects and collects circular references. The garbage collector begins with local and static and it marks each object that can be reached through their children.Through this, you can handle the issues with circular references.Let’s say the following classes is in circular reference. Here both of them depends on each other −public class A { B Two; } public class B { A one; }To solve the ... Read More
371 Views
The Array.SyncRoot property is used to get an object that can be used to synchronize access to the Array. The classes that have arrays can also use the SyncRoot property to implement their own synchronization.Enumerating through a collection is not a thread safe procedure. The other threads may modify the collection even when the collection is synchronized. This would eventually cause the enumerator to throw an exception. For this, you need to lock the collection.Let us see an example to work with Array.SyncRoot property −Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { ... Read More
262 Views
C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg.C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.The following are some of the features of C++ missing in C# −In C#, Multiple Inheritance is not possible, whereas C++ can easily implement Multiple Inheritance.In C++, you need to manage memory manually and must allocate and deallocate memory for your objects.C++ can create standalone applications, whereas C# ... Read More