George John has Published 1167 Articles

C# program to display the previous day

George John

George John

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

3K+ Views

To display the previous day, use the AddDays() method and a value -1 to get the previous day.Firstly, use the following to get the current day −DateTime.TodayNow, add -1 to the AddDays() method to get the previous day −DateTime.Today.AddDays(-1)The following is the code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; ... Read More

C# Program to Add Two TimeSpan

George John

George John

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

495 Views

Firstly, set two TimeSpans −TimeSpan t1 = TimeSpan.FromMinutes(1); TimeSpan t2 = TimeSpan.FromMinutes(2);To add it, use the Add() method −TimeSpan res = t1.Add(t2);ExampleUsing System; using System.Linq; public class Demo {    public static void Main() {       TimeSpan t1 = TimeSpan.FromMinutes(1);       TimeSpan t2 = TimeSpan.FromMinutes(2);   ... Read More

Combine two arrays in C#

George John

George John

Updated on 22-Jun-2020 13:56:18

4K+ Views

Firstly, declare and initialize two arrays −int[] arr1 = { 37, 45, 65 }; int[] arr2 = { 70, 89, 118 };Now create a new list −var myList = new List(); myList.AddRange(arr1); myList.AddRange(arr2);Use the AddRange() method the arrays into the newly created list.myList.AddRange(arr1); myList.AddRange(arr2);Now convert the list into array as ... Read More

Replace a C# array with a new array of different size

George John

George John

Updated on 22-Jun-2020 13:53:43

770 Views

To replace a C# aray with a new array, use the Array.Resize.Withing that, set the size of the new array −Array.Resize(ref arr, 4);Now add the new elements to the array as shown below −Example Live Demousing System; class Program {    static void Main() {       char[] arr = ... Read More

C# program to create an empty string array

George John

George John

Updated on 22-Jun-2020 13:51:23

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

Bool Array in C#

George John

George John

Updated on 22-Jun-2020 13:49:25

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

The nameof keyword in C#

George John

George John

Updated on 22-Jun-2020 13:47:39

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

File Permissions in C#

George John

George John

Updated on 22-Jun-2020 13:21:18

2K+ Views

For File Permission in C#, use the FileIOPermission Class. It controls the ability to access files and folders.The following are the properties of File Permissions class −Sr.No.Methods & Description1AllFilesGets or sets the permitted access to all files.2AllLocalFilesGets or sets the permitted access to all local files.The following are the methods ... Read More

String slicing in C# to rotate a string

George John

George John

Updated on 22-Jun-2020 13:08:40

313 Views

Let’s say our string is −var str = "welcome";Use the substring() method and the following, if you want to rotate only some characters. Here, we are rotating only 2 characters −var res = str.Substring(1, str.Length - 1) + str.Substring(0, 2);The following is the complete code −Example Live Demousing System; public ... Read More

How can we create a MySQL view based on another existing view?

George John

George John

Updated on 22-Jun-2020 13:07:56

279 Views

In MySQL, we can create a view that is based on another existing view. To make it understand we are having the view ‘Info’ with the following data −mysql> Create view info AS Select Id, Name, Subject FROM student_info; Query OK, 0 rows affected (0.11 sec) mysql> Select * ... Read More

Advertisements