What are Dynamic Data Types in C#

George John
Updated on 20-Jun-2020 16:35:50

618 Views

Store any type of value in the dynamic data type variable. Type checking for these types of variables takes place at run-time.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 run time.

Overloaded Indexers in C#

Chandu yadav
Updated on 20-Jun-2020 16:35:18

819 Views

An indexer in C# allows an object to be indexed such as an array. When an indexer for a class is defined, this class behaves similar to a virtual array. You can then access the instance of this class using the array access operator ([ ]).Indexers can be overloaded. Indexers can also be declared with multiple parameters and each parameter may be a different type.The following is an example of overloaded indexers in C# −Example Live Demousing System; namespace IndexerApplication {    class IndexedNames {       private string[] namelist = new string[size];       static public int size ... Read More

Literals in C#

Arjun Thakur
Updated on 20-Jun-2020 16:32:18

3K+ Views

The fixed values are called literals. The constants refer to fixed values that the program may not alter during its execution.Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal. There are also enumeration constants as well.Let us learn about integer, float, and string literals in C# −Integer LiteralsAn integer literal can be a decimal, or hexadecimal constant. A prefix specifies the base or radix: 0x or 0X for hexadecimal, and there is no prefix id for decimal.Here are some example of Integer Literals −20 // ... Read More

What is String Title Case in C#

Ankith Reddy
Updated on 20-Jun-2020 16:31:55

2K+ Views

The ToTitleCase method is used to capitalize the first letter in a word. Title case itself means to capitalize the first letter of each major word.Let us see an example to get the title case −Example Live Demousing System; using System.Globalization; class Demo {    static void Main() {       string str = "jack sparrow";       string res = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str);       Console.WriteLine(res);    } }OutputJack SparrowAbove, we have set the input string to the ToTitleCase() method. The CultureInfo.TextInfo property is used to provide the culture-specific casing information for strings −CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str);

Array SyncRoot Property in C#

Arjun Thakur
Updated on 20-Jun-2020 16:31:20

375 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

What are Circular References in C#

Ankith Reddy
Updated on 20-Jun-2020 16:30:28

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

Use of Using Statement in C#

George John
Updated on 20-Jun-2020 16:29:25

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

What are String Literals in C#

Arjun Thakur
Updated on 20-Jun-2020 16:28:38

428 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!

What are Floating Point Literals in C#

Ankith Reddy
Updated on 20-Jun-2020 16:27:44

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

What are I/O Classes in C#

Chandu yadav
Updated on 20-Jun-2020 16:22:55

959 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

Advertisements