Keys Property of SortedList Class in C#

Arjun Thakur
Updated on 23-Jun-2020 10:49:39

111 Views

Get the keys in the SortedList using the keys property of SortedList class in C#. We have first set the SortedList property with elements.SortedList sl = new SortedList(); sl.Add("ST0", "One"); sl.Add("ST1", "Two"); sl.Add("ST2", "Three"); sl.Add("ST3", "Four"); sl.Add("ST4", "Five"); sl.Add("ST5", "Six"); sl.Add("ST6", "Seven");Now use the keys property to get the keys.ICollection key = sl.Keys;The following is the complete code to implement keys property of SortedList class.Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          SortedList sl = new SortedList();          sl.Add("ST0", "One");   ... Read More

IsFixedSize Property of SortedList Class in C#

George John
Updated on 23-Jun-2020 10:05:00

125 Views

Use the IsFixedSize property in C# to get a value indicating whether the SortedList has a fixed size.The following is an example showing SorteList with the usage of IsFixedSize property.Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          SortedList s = new SortedList();          s.Add("S1", "Maths");          s.Add("S2", "Science");          s.Add("S3", "English");          s.Add("S4", "Economics");          Console.WriteLine("IsFixedSize = " + s.IsFixedSize);       }    } }OutputIsFixedSize = FalseWe ... Read More

IsReadOnly Property of SortedList Class in C#

Arjun Thakur
Updated on 23-Jun-2020 10:03:48

125 Views

Use the IsReadOnly property to get a value indicating whether the SortedList is read-only or not.You can try to run the following code to implement IsReadOnly property in C#.Here, we have set the SortedList first.SortedList s = new SortedList();Added elements.s.Add("S001", "Jack"); s.Add("S002", "Henry");Now check for IsReadOnly.Console.WriteLine("IsReadOnly = " + s.IsReadOnly);The following is the complete code.Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          SortedList s = new SortedList();          s.Add("S001", "Jack");          s.Add("S002", "Henry");          Console.WriteLine("IsReadOnly ... Read More

Character Constants vs String Literals in C#

karthikeya Boyini
Updated on 23-Jun-2020 10:03:16

498 Views

Character constantsCharacter literals are enclosed in single quotes. For example, 'x' and can be stored in a simple variable of char type. A character literal can be a plain character (such as 'x'), an escape sequence (such as '\t'), or a universal character (such as '\u02C0').Certain characters in C# are preceded by a backslash. They have special meaning and they are used to represent like newline () or tab (\t).Example Live Demousing System; namespace Demo {    class MyApplication {       static void Main(string[] args) {          Console.WriteLine("Welcome\t to the website");          Console.ReadLine(); ... Read More

Check If a File Exists in C#

Samual Sam
Updated on 23-Jun-2020 10:02:16

10K+ Views

Use the File.exists method in C# to check if a file exits in C# or not.Firstly, check whether the file is present in the current directory.if (File.Exists("MyFile.txt")) {    Console.WriteLine("The file exists."); }After that check whether the file exist in a directory or not.if (File.Exists(@"D:\myfile.txt")) {    Console.WriteLine("The file exists."); }Let us see the complete example to check if a file exists in C#.Example Live Demousing System; using System.IO; class Demo {    static void Main() {       if (File.Exists("MyFile.txt")) {          Console.WriteLine("File exists...");       } else {          Console.WriteLine("File does ... Read More

IsFixedSize Property of Hashtable Class in C#

karthikeya Boyini
Updated on 23-Jun-2020 10:01:24

124 Views

Use the isFixedSize property of Hashtable class to get a value indicating whether the Hashtable has a fixed size.The following is an example showing how to work with IsFixedSize property.Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          Hashtable ht = new Hashtable();          ht.Add("D01", "Finance");          ht.Add("D02", "HR");          ht.Add("D03", "Operations");          Console.WriteLine("IsFixedSize = " + ht.IsFixedSize);          Console.ReadKey();       }    } }OutputIsFixedSize = FalseAbove we ... Read More

Check If Both Halves of the String Have Same Set of Characters in C#

George John
Updated on 23-Jun-2020 10:00:49

221 Views

Firstly, set the string to be checked.string s = "timetime";Now set two counters for two halves of the string.int []one = new int[MAX_CHAR]; int []two = new int[MAX_CHAR];Check for both the halves of the string.for (int i = 0, j = l - 1; i < j; i++, j--) {    one[str[i] - 'a']++;    two[str[j] - 'a']++; }The following is the complete code to check whether both the halves of the string have same set of characters or not in C#.Example Live Demousing System; class Demo {    static int MAX_CHAR = 26;    static bool findSameCharacters(string str) {   ... Read More

Set Starting Position of Background Image in JavaScript DOM

Sharon Christine
Updated on 23-Jun-2020 10:00:38

530 Views

To set the starting position of a background image in JavaScript, use the backgroundposition property. It allows you to set the position of the image.ExampleYou can try to run the following code to learn how to set all the position of a background image with JavaScript −Live Demo                    body {             background-repeat: no-repeat;          }                     Click to Set background image                function display() {             document.body.style.backgroundImage = "url('https://www.tutorialspoint.com/html5/images/html5-mini-logo.jpg')";             document.body.style.backgroundPosition="top right";          }          

C# Program to Accept Two Integers and Return the Remainder

karthikeya Boyini
Updated on 23-Jun-2020 09:58:59

704 Views

Firstly, set the two numbers.int one = 250; int two = 200;Now pass those numbers to the following function.public int RemainderFunc(int val1, int val2) {    if (val2 == 0)    throw new Exception("Second number cannot be zero! Cannot divide by zero!");    if (val1 < val2)    throw new Exception("Number cannot be less than the divisor!");    else    return (val1 % val2); }Above we have checked for two conditions i.e.If the second number is zero, an exception occurs.If the first number is less than the second number, an exception occurs.To return remainder of two numbers, the following is ... Read More

Convert 'is' to Number in JavaScript

karthikeya Boyini
Updated on 23-Jun-2020 09:58:50

122 Views

Use the Number() method in JavaScript to convert to Number. You can try to run the following code to learn how to convert ["demo"] to Number in JavaScript −ExampleLive Demo           Convert ["demo"] to Number                var myVal = ["demo"];          document.write("Number: " + Number(myVal));          

Advertisements