Karthikeya Boyini has Published 2383 Articles

How to validate a string for a numeric representation using TryParse in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 15:14:57

269 Views

The following is our string −string myStr = "5";To check whether the above is a string with numeric representation, use TryParse and out.int.TryParse(myStr, out a);Here is the complete code.Example Live Demousing System.IO; using System; class Program {    static void Main() {       bool res;       int ... Read More

Program to get the last element from an array using C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 15:14:13

3K+ Views

Declare an array and add elements.int[] val = { 5, 8, 15, 25, 40, 55, 80, 100 };Now, use the Queryable Last() method to get the last element.val.AsQueryable().Last();Let us see the complete code.Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo {    static void Main() {       ... Read More

The Fibonacci sequence in Javascript

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 15:00:49

379 Views

Fibonacci numbers are the numbers such that every number in the series after the first two is the sum of the two preceding ones. The series starts with 1, 1. Example −1, 1, 2, 3, 5, 8, 13, 21, 34, ….We can write a program to generate nth as follows −functionfibNaive(n) {    if (n

C# Program to display temporary file names

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:55:40

154 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/

C# Program to find the largest element from an array

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:51:48

2K+ Views

Declare an array −int[] arr = { 20, 50, -35, 25, 60 };Now to get the largest element from an array, use the Max() method −arr.Max());Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       int[] arr = { 20, 50, -35, 25, 60 };       Console.WriteLine(arr.Max());    } }Output60

Group by Operator in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:51:03

123 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 = ... Read More

Long.parse method in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:50:11

1K+ 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"; ... Read More

Round a number to the nearest even number in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:49:23

606 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 { ... Read More

Decimal constants in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:48:39

2K+ 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() ... Read More

C# Program to get the last write time of a file

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:44:14

2K+ Views

To get the last write time of a file in C#, use the LastWriteTime() method.For this, use the FileInfo as well as DateTime classes.Create an object of each −FileInfo file = new FileInfo("amit.txt"); DateTime dt = file.CreationTime; dt = file.LastWriteTime;Let us see the complete code −Example Live Demousing System.IO; using System; ... Read More

Advertisements