Programming Articles - Page 3149 of 3363

Ways to print escape characters in C#

Chandu yadav
Updated on 20-Jun-2020 16:46:28

1K+ Views

The following are the escape characters in C# and the display column suggests how to use and print them in C# −Escape CharacterDescriptionPatternDisplay\aMatches a bell character, \u0007.\a"\u0007" in "Warning!" + '\u0007'\bIn a character class, matches a backspace, \u0008.[\b]{3, }"\b\b\b\b" in "\b\b\b\b"\tMatches a tab, \u0009.(\w+)\t"Name\t", "Addr\t" in "Name\tAddr\t"\rMatches a carriage return, \u000D. (\r is not equivalent to the newline character, .)\r(\w+)"\rHello" in "\r\HelloWorld."\vMatches a vertical tab, \u000B.[\v]{2, }"\v\v\v" in "\v\v\v"\fMatches a form feed, \u000C.[\f]{2, }"\f\f\f" in "\f\f\f"Matches a new line, \u000A.\r(\w+)"\rHello" in "\r\HelloWorld."\eMatches an escape, \u001B.\e"\x001B" in "\x001B"nnUses octal representation to specify a character (nnn consists of up to three digits).\w\040\w"a ... Read More

Way to increment a character in C#

Arjun Thakur
Updated on 20-Jun-2020 16:46:52

2K+ Views

Firstly, set a character−char ch = 'K';Now simply increment it like this −ch++;If you will print the character now, it would be the next character as shown in the following example −Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       char ch = 'K';       Console.WriteLine("Initial character:"+ch);       // increment character       ch++;       Console.WriteLine("New character:"+ch);    } }OutputInitial character:K New character:L

Hashtable vs. Dictionary in C#

Chandu yadav
Updated on 20-Jun-2020 16:47:09

1K+ Views

HashtableA hash table is used when you need to access elements by using key, and you can identify a useful key value. Each item in the hash table has a key/value pair. The key is used to access the items in the collection.The members in a Hashtable are thread safe. It returns null if we try to find a key that does not exist. Hashtable is not a generic type.The Hashtable collection is slower than dictionary because it requires boxing and unboxing.To declare a Hashtable −Hashtable ht = new Hashtable();DictionaryDictionary is a collection of keys and values in C#. Dictionary ... Read More

What are lambda expressions in C#?

George John
Updated on 20-Jun-2020 16:47:32

330 Views

A lambda expression in C# describes a pattern. It has the token => in an expression context. This is read as “goes to” operator and used when a lambda expression is declared.The following is an example showing how to use lambda expressions in C# −Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       List list = new List() { 21, 17, 40, 11, 9 };       int res = list.FindIndex(x => x % 2 == 0);       Console.WriteLine("Index: "+res);    } }OutputIndex: 2Above, we saw the usage of ... 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);

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 are overloaded indexers in C#?

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

816 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

What are dynamic data types in C#?

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

615 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.

What are identifiers in C#?

Arjun Thakur
Updated on 20-Jun-2020 16:37:21

1K+ Views

An identifier is a name used to identify a class, variable, function, or any other user-defined item. The basic rules for naming classes in C# are as follows −A name must begin with a letter that could be followed by a sequence of letters, digits (0 - 9) or underscore. The first character in an identifier cannot be a digit.It must not contain any embedded space or symbol such as? - + ! @ # % ^ & * ( ) [ ] { } . ; : " ' / and \. However, an underscore ( _ ) can ... Read More

What are key-based I/O collections in C#?

Chandu yadav
Updated on 20-Jun-2020 16:38:04

231 Views

The key-based I/O Collections in C# is what we call a SortedList −SortedListThe SortedList class represents a collection of key-and-value pairs that are sorted by the keys and are accessible by key and by index. This is how both of them gets added in a SortedList −s.Add("Sub1", "Physics"); s.Add("Sub2", "Chemistry"); s.Add("Sub3", "Biology"); s.Add("Sub4", "Java");The following is an example displaying the keys and values in a SortedList −Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          SortedList s = new SortedList();       ... Read More

Advertisements