Found 2628 Articles for Csharp

What are integer literals in C#?

Arjun Thakur
Updated on 20-Jun-2020 16:44:54

432 Views

An 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. It can also have a suffix that is a combination of U and L, for unsigned and long, respectively.Here are some of the examples of integer literals −200 // int 90u// unsigned intLet’s use the above literal while declaring and initializing a variable −// int int a =200;We will now print the values −Example Live Demousing System; namespace Demo {    class Program {       static ... Read More

Way to read input from console in C#

George John
Updated on 20-Jun-2020 16:45:59

16K+ Views

Use the ReadLine() method to read input from the console in C#. This method receives the input as string, therefore you need to convert it.For example −Let us see how to get user input from user and convert it to integer.Firstly, read user input −string val; Console.Write("Enter integer: "); val = Console.ReadLine();Now convert it to integer −int a = Convert.ToInt32(val); Console.WriteLine("Your input: {0}", a);Let us see this in an example. The input is added using command line argument−Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       string val;       Console.Write("Enter ... Read More

Ways to print escape characters in C#

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

727 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

939 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

179 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

2K+ 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

535 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

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

Advertisements