- 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 34494 Articles for Programming
1K+ Views
The ReadLine() method is used to read a line from the console in C#.str = Console.ReadLine();The above will set the line in the variable str.Example Live Demousing System; using System.Collections.Generic; class Demo { static void Main() { string str; // use ReadLine() to read the entered line str = Console.ReadLine(); // display the line Console.WriteLine("Input = {0}", str); } }OutputInput =Above, we displayed a line using the Console.ReadLine() method. The string is entered by the user from the command line.
347 Views
Threads are lightweight processes. Each thread defines a unique flow of control. The life cycle of a thread starts when an object of the System.Threading.Thread class is created and ends when the thread is terminated or completes execution.Here are the various states in the life cycle of a thread −The Unstarted StateIt is the situation when the instance of the thread is created but the Start method is not called.The Ready StateIt is the situation when the thread is ready to run and waiting CPU cycle.The Not Runnable StateA thread is not executable, whenSleep method has been calledWait method has been ... Read More
445 Views
A lambda expression in C# describes a pattern.Lambda Expressions has the token => in an expression context. This is read as “goes to” operator and used when a lambda expression is declared.Here, we are finding the first occurrence of the element greater than 50 from a list.list.FindIndex(x => x > 50);Above the token => is used. The same is shown below −Example Live Demousing System; using System.Collections.Generic; class Demo { static void Main() { List list = new List { 44, 6, 34, 23, 78 }; int res = list.FindIndex(x => x > 50); Console.WriteLine("Index: "+res); } }OutputIndex: 4
484 Views
Keywords are reserved words predefined to the C# compiler. These keywords cannot be used as identifiers. However, if you want to use these keywords as identifiers, you may prefix the keyword with the @ character.The following are the two types of keywords in C#.Reserved KeywordsabstractasbaseBoolbreakbytecasecatchcharcheckedClassconstcontinuedecimaldefaultdelegatedoDoubleelseenumeventexplicitexternfalseFinallyfixedfloatforforeachgotoifImplicitinin (generic modifier)intinterfaceinternalisLocklongnamespacenewnullobjectoperatorOutout (generic modifier)overrideparamsprivateprotectedpublicReadonlyrefreturnsbytesealedshortsizeofstackallocstaticstringstructswitchthisthrowTruetrytypeofuintulonguncheckedunsafeUshortusingvirtualvoidvolatilewhileContextual Keywordsaddaliasascendingdescendingdynamicfromgetglobalgroupintojoinletorderbypartial (type)partial(method)removeselectset
366 Views
To display large Fibonacci numbers, try the following login and code.Here, we have set the value of n as the series. Set it to get the Fibonacci number. Below, we have set it to 100 to get the first 100 Fibonacci numbers.Since the first two numbers in a Fibonacci series are 0 and 1. Therefore, we will set the first two values.int val1 = 0, val2 = 1;The following is the complete code to display large Fibonacci numbers.Example Live Demousing System; public class Demo { public static void Main(string[] args) { int val1 = 0, val2 = ... Read More
314 Views
A regular expression is a pattern that could be matched against an input text. A pattern consists of one or more character literals, operators, or constructs.Let us see an example to display the words starting with the letter ‘M’ using Regex.Example Live Demousing System; using System.Text.RegularExpressions; namespace Demo { class Program { private static void showMatch(string text, string expr) { Console.WriteLine("The Expression: " + expr); MatchCollection mc = Regex.Matches(text, expr); foreach (Match m in mc) { Console.WriteLine(m); ... Read More
232 Views
To pass arrays to methods, you need to pass an array as a method argument.int displaySum(int[] arr, int size) { }Now call it −sum = d.displaySum(myArr, 5 ) ;Example Live Demousing System; namespace Test { class Demo { int displaySum(int[] arr, int size) { int i; int sum = 0; for (i = 0; i < size; ++i) { sum += arr[i]; } return sum; } static void Main(string[] args) { Demo d = new Demo(); int [] myArr = new int[] {59, 34, 76, 65, 12, 99}; int sum; sum = d.displaySum(myArr, 5 ) ; /* output the returned value */ Console.WriteLine( "Sum: {0} ", sum ); Console.ReadKey(); } } }OutputSum: 246
476 Views
To quickly convert decimal to other bases, use Stacks. Let us see an example.Firstly, I have set the variable “baseNum” as 2int baseNum = 2;In the same way, if you want another base, then −// base 8 int baseNum = 8; // base 10 int baseNum = 10;After getting the value, set a stack and get the values by getting the remainder and other calculations as shown below.Here, n is the decimal number.Stack s = new Stack(); do { s.Push(n % baseNum); n /= baseNum; } while (n != 0);After using the stack, pop out the elements. ... Read More
2K+ Views
First, set a two-dimensional array.int[, ] arr = new int[10, 10];Now, get the elements from the user −for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { arr[i, j] = Convert.ToInt16(Console.ReadLine()); } }Let us see the complete example to display the matrix.Example Live Demousing System; using System.Linq; class Demo { static void Main() { int m, n, i, j; // rows and columns of the matrix+ m = 2; n = ... Read More