Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 2453 of 2650
2K+ Views
To randomize string, firstly use Random class −Random r = new Random();Now, use the Next() method with OrderBy() −string random = new string(str.ToCharArray().OrderBy(s => (r.Next(2) % 2) == 0).ToArray());Here is the compete code that displays randomize string −Example Live Demousing System; using System.IO; using System.Linq; class Demo { static void Main() { const string str = "electronics"; Random r = new Random(); string random = new string(str.ToCharArray().OrderBy(s => (r.Next(2) % 2) == 0).ToArray()); Console.WriteLine("String = {0}", str); Console.WriteLine("Random String = {0}",random); Console.Read(); } }OutputString = electronics Random String = lericsecton
242 Views
The GetTempPath() method in C# displays temporary file names −Path.GetTempPath();Get the names in a variable and display −string tempFile = Path.GetTempPath();The following is the code −Example Live Demousing System; using System.IO; class Demo { static void Main() { string tempFile = Path.GetTempPath(); Console.WriteLine(tempFile); } }Output/tmp/
246 Views
With C#, you can manipulate decimals with operators such as _+, - *, etc.Let us see how to subtract decimal values.Firstly, set two decimal values −decimal d1 = 9.5M; decimal d2 = 4.2M;Now to subtract the two values −d1 = d1 - d2;The following is the code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { decimal d1 = 9.5M; decimal d2 = 4.2M; d1 = d1 + d2; Console.WriteLine("Addition of Decimals: "+d1); d1 = d1 - d2; Console.WriteLine("Subtraction of Decimals: "+d1); } }OutputAddition of Decimals: 13.7 Subtraction of Decimals: 9.5
3K+ Views
Decimal type has constants to get the minimum and maximum values.Set a decimal value −decimal d = 5.8M;To get the minimum and maximum values of the decimal type, use the following properties −decimal.MaxValue decimal.MinValueHere is the complete code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { decimal d = 5.8M; Console.WriteLine(d); Console.WriteLine("Maximum Value: "+decimal.MaxValue); Console.WriteLine("Maximum Value: "+decimal.MinValue); } }Output5.8 Maximum Value: 79228162514264337593543950335 Maximum Value: -79228162514264337593543950335
2K+ Views
The decimal type is a value type and has the plus, minus, multiply and divide operators. Firstly, set two decimal values − decimal d1 = 5.8M; decimal d2 = 3.2M; To add decimals − d1 = d1 + d2; Let us see an example to add two decimal values − Example Live Demo using System; using System.Linq; class Demo { static void Main() { decimal d1 = 5.8M; decimal d2 = 3.2M; d1 = d1 + d2; Console.WriteLine(d1); } } Output 9.0
796 Views
The ToEven property is used with the MidpointRounding Enumeration to round a number to the nearest even number.Declare and initialize a decimal number −decimal val = 25.55M;To round a number to the nearest even number −decimal.Round(val, 0, MidpointRounding.ToEven)Here is the complete code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { decimal val = 25.55M; Console.WriteLine(decimal.Round(val, 0, MidpointRounding.ToEven)); } }Output26
4K+ Views
Use the Truncate method in C# to remove all the number after decimal places.Let’s say the following is our number −9.15MTo remove the numbers after decimal places, use Truncate() −decimal.Truncate(9.15M)Let us see the complete code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { decimal val = 9.15M; Console.WriteLine(decimal.Truncate(val)); } }Output9
2K+ Views
To convert a string to a long, use the Long.parse method in C# −Firstly, set a string −string str = "7864646475767";Now, convert it to long −long.Parse(str);Here is the complete code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { string str = "7864646475767"; long res = long.Parse(str); Console.WriteLine(res); } }Output7864646475767
174 Views
To convert a string to a bool, use the Bool.parse method in C# −Firstly, set a string −string str = "true";Now, convert it to bool −bool.Parse(str);Here is the complete code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { string str = "true"; bool res = bool.Parse(str); Console.WriteLine(res); } }OutputTrue
188 Views
Use the group by the operator in C# to separate the results of an expression into parts.Let’s say the following is our array −int[] a = { 5, 10, 15, 20, 25, 30 };Now, using Group by and orderby, we will find the elements greater than 20 −var check = from element in a orderby element group element by chkGreater(element);The following is the complete code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { int[] a = { 5, 10, 15, 20, 25, 30 }; var check = from element ... Read More