- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34487 Articles for Programming
488 Views
The nameof operator returns a string literal of an element that can be a variable, type or member.For example, the following is our variable −var vehicle = "motorbike";To get the string literal, use nameof −nameof(vehicle);The following is the code to implement nameof keyword −Example Live Demousing System; public class Program { static void Main() { var vehicle = "motorbike"; Console.WriteLine(nameof(vehicle)); var time = DateTime.Now.ToLocalTime(); Console.WriteLine(nameof(time)); var a = false; Console.WriteLine(nameof(a)); } }Outputvehicle time a
2K+ Views
Use the default operator to get the default value of bool type −bool a = default(bool);Above, we have used the default keyword to get the default value.Let us see the code to display default value of bool −Example Live Demousing System; public class Demo { public static void Main() { bool a = default(bool); // default for bool Console.WriteLine("Default for bool type = "+a); } }OutputThe following is the output. It shows a blank space i.e. False.Default for bool type = False
428 Views
Use the default operator to get the default value of StringBuilder.StringBuilder str = default(StringBuilder);Above, we have used the default keywords to get the default value.Let us see the complete code −Example Live Demousing System; using System.Text; public class Demo { public static void Main() { StringBuilder str = default(StringBuilder); Console.WriteLine("Default for StringBuilder = "+str); } }OutputDefault for StringBuilder =The following is the output. It shows a blank space i.e. Null.Default for StringBuilder = Null
519 Views
Using the default, you can get the default value of every reference and value type. The expressions set as default are evaluated at compile-time.To get the default for int −default(int);To get the default for long −default(long)Let us see the code to display default values −Example Live Demousing System; public class Demo { public static void Main() { int val1 = default(int); long val2 = default(long); bool val3 = default(bool); // default for int Console.WriteLine(val1); // default for long Console.WriteLine(val2); // default for bol Console.WriteLine(val3); } }Output0 0 False
7K+ Views
In a bool array, you can store true and false values. To set a bool array, use the new operator −bool[] arr = new bool[5];To add elements in the array −arr[0] = true; arr[1] = true; arr[2] = false; arr[3] = true; arr[4] = true;Let us see the complete code −Example Live Demousing System; public class Demo { public static void Main() { bool[] arr = new bool[5]; arr[0] = true; arr[1] = true; arr[2] = false; arr[3] = true; arr[4] = true; Console.WriteLine("Displaying values..."); foreach (bool res in arr) { Console.WriteLine(res); } } }OutputDisplaying values... True True False True True
41 Views
The following is the string array −string[] str = { "Java", "AngularJS", "Python", "jQuery", "HTML5" };Firstly, join it −string.Join(" ", str);Now to separate the above joined strings, use the Split() method as shown in the following code −Example Live Demousing System; public class Demo { public static void Main() { string[] str = { "Java", "AngularJS", "Python", "jQuery", "HTML5" }; // join words string res = string.Join(" ", str); Console.WriteLine("Joined Strings... "+res); string[] convert = res.Split(' '); Console.WriteLine("Separate Joined Strings..."); ... Read More
182 Views
Declare a string and add elements −string[] str = { "One", "Two", "Three", "Four", "Five" };Use the Join() method to join the words−string res = string.Join(" ", str);Let us see the complete code −Example Live Demousing System; public class Demo { public static void Main() { string[] str = { "One", "Two", "Three", "Four", "Five" }; // join words string res = string.Join(" ", str); Console.WriteLine(res); } }OutputOne Two Three Four Five
473 Views
Declare and initialize an array −string[] str = new string[] { "Cat", "Mat", "Rat" };Now, ue IndexOf() method to find the index of the word “Mat” −Array.IndexOf(str, "Mat");The following is the code −Example Live Demousing System; public class Demo { public static void Main() { string[] str = new string[] { "Cat", "Mat", "Rat" }; Console.WriteLine("Our Array ="); for (int i = 0; i < str.Length; i++) { string res = str[i]; Console.WriteLine(res); } int findIndex = Array.IndexOf(str, "Mat"); Console.Write("Element Mat found at the following index: "); Console.WriteLine(findIndex); } }OutputOur Array = Cat Mat Rat Element Mat found at the following index: 1
3K+ Views
To create an empty string array −string[] str = new string[] {};Above, we haven’t added elements to the array, since it is empty.Even if we will loop though the array, it won’t display anything as shown below −Example Live Demousing System; public class Demo { public static void Main() { string[] str = new string[] {}; Console.WriteLine("String Array elements won't get displayed since it's empty..."); for (int i = 0; i < str.Length; i++) { string res = str[i]; Console.WriteLine(res); } } }OutputString Array elements won't get displayed since it's empty...
2K+ Views
Create a string array −string[] str = new string[] { "Videos", "Tutorials", "Tools", "InterviewQA" };Loop until the length of the array −for (int i = 0; i < str.Length; i++) { string res = str[i]; Console.WriteLine(res); }Here is the complete code −Example Live Demousing System; public class Demo { public static void Main() { string[] str = new string[] { "Videos", "Tutorials", "Tools", "InterviewQA" }; Console.WriteLine("String Array..."); for (int i = 0; i < str.Length; i++) { string res = str[i]; Console.WriteLine(res); } } }OutputString Array... Videos Tutorials Tools InterviewQA