Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Chandu yadav
Page 13 of 81
C# program to convert string to long
To convert a string to a long, use the Long.parse method in C# −Firstly, set a string −string str = "6987646475767";Now, convert it to long −long.Parse(str);Here is the complete code −Exampleusing System; using System.Linq; class Demo { static void Main() { string str = "6987646475767"; long res = long.Parse(str); Console.WriteLine(res); } }Output6987646475767
Read MoreUsage of Bootstrap class panel-danger
The .panel-danger class in Bootstrap is used to indicate danger.You can try to run the following code to implement panel-danger class −Example Bootstrap Example Panel title (danger) This is a Basic panel
Read MoreKeyNotFoundException in C#
The KeyNotFoundException is thrown when a key you are finding is not available in the Dictionary collection.Let us see an example −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main() { try { var dict = new Dictionary() { {"TV", "Electronics"}, {"Laptop", "Computers"}, }; Console.WriteLine(dict["Pen Drive"]); } catch (Exception e) { Console.WriteLine(e); } } }The ...
Read MoreWhat is the Count property of SortedList class in C#?
Exampleusing System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { SortedList s = new SortedList(); s.Add("S1", "Electronics"); s.Add("S2", "Clothing"); s.Add("S3", "Applicances"); s.Add("S4", "Books"); s.Add("S5", "Accessories"); s.Add("S6", "Musical Instruments"); Console.WriteLine("Count = " + s.Count); } } }OutputCount = 6
Read MoreCreate Dismissal Alerts in Bootstrap
To create a dismissal alert −Add a basic alert by creating a wrapper and adding a class of .alert and one of the four contextual classes, for example, .alert-success, .alert-info, etc.Also add optional .alert-dismissable to the above class.Add a close button.You can try to run the following code to create dismissal alerts −Example Bootstrap Example × Success! Well done its submitted. × Info! Take this info.
Read MoreWhy is the Main() method use in C# static?
The Main method states what the class does when executed and instantiates other objects and variables.A main method is static since it is available to run when the C# program starts. It is the entry point of the program and runs without even creating an instance of the class.The following shows how to add a Main() method with static −Exampleusing System; namespace Demo { class HelloWorld { static void Main(string[] args) { Console.WriteLine("Bingo!"); Console.ReadKey(); } } }OutputBingo!As you can see in the ...
Read MoreAll Method in C#
The All() extension method is part of the System.Linq namepspace. Using this method, you can check whether all the elements match a certain condition or not.Set an array −int[] arr = { 6, 7, 15, 40, 55 };The following is an example. It checks whether all the elements in the array is greater than and equal to 2 or not −arr.All(element => element > = 2);Here is the complete code −Exampleusing System; using System.Linq; class Program { static void Main() { int[] arr = { 6, 7, 15, 40, 55 }; bool res = arr.All(element => element >= 2); Console.WriteLine(res); } }OutputTrue
Read MoreHow to generate the first 100 Odd Numbers using C#?
To generate first 100 odd numbers, set a for loop from 1 to 100.for(val = 1; val
Read MoreDifferent ways for Integer to String Conversions in C#
The easiest way to convert an integer to a string in C# is using the ToString() method.Let us see an example −int a = 100; string str = a.ToString();Another way is to use Convert.ToString();b = 50; string str2 = Convert.ToString(b); Console.WriteLine(str2);The following is the example showing the different ways to convert integer to string.Exampleusing System; class Program { static void Main() { int a, b, c; a = 10; string str = a.ToString(); Console.WriteLine(str); b = 50; string str2 = Convert.ToString(b); Console.WriteLine(str2); c = 100; string str3 = string.Format("{0}", c); Console.WriteLine(str3); } }Output10 50 100
Read MoreC# Program to split a string on spaces
Firstly, set a string −string str = "Science and Mathematics";Now use the Split() method to split wherever the spaces occur −str.Split(' ')The following is the complete code −Exampleusing System; using System.Linq; using System.IO; class Program { static void Main() { string str = "Science and Mathematics"; Console.WriteLine("String..."+str); string[] myStr = str.Split(' '); Console.WriteLine("Splitted String..."); foreach (string ch in myStr) { Console.WriteLine(ch); } } }OutputString... Science and Mathematics Splitted String... Science and Mathematics
Read More