Null List in C#

Samual Sam
Updated on 22-Jun-2020 14:05:11

2K+ Views

A null list exists in C#. To check whether a list is null or not, check them against the null literal. Set a null like this −List myList = null;Now, to check for null, use the equality operator −myList == null;The following is an example −Example Live Demousing System; using System.Collections.Generic; using System.Linq; public class Demo {    public static void Main() {       List myList = null;       // checking for null       Console.WriteLine(myList == null);    } }OutputTrue

C# Program to Subtract Two Timespan

karthikeya Boyini
Updated on 22-Jun-2020 14:04:46

479 Views

Firstly, set two TimeSpans −TimeSpan t1 = TimeSpan.FromMinutes(2); TimeSpan t2 = TimeSpan.FromMinutes(1);To add it, use the Subtract() method −imeSpan res = t1.Subtract(t2);Here is the complete code −Example Live Demousing System; using System.Linq; public class Demo {    public static void Main() {       TimeSpan t1 = TimeSpan.FromMinutes(2);       TimeSpan t2 = TimeSpan.FromMinutes(1);       Console.WriteLine("First TimeSpan: "+t1);       Console.WriteLine("Second TimeSpan: "+t2);       // Subtracting       TimeSpan res = t1.Subtract(t2);       Console.WriteLine("Resultant TimeSpan: "+res);    } }OutputFirst TimeSpan: 00:02:00 Second TimeSpan: 00:01:00 Resultant TimeSpan: 00:01:00

Buffer SetByte Example in C#

Chandu yadav
Updated on 22-Jun-2020 14:03:27

322 Views

The SetByte() method assigns a specified value to a byte at a particular location in a specified array.Firstly, set an array −int[] arr = { 3, 4, 12 };Now, use SetByte() to assign values −Buffer.SetByte(arr, 3, 20);Here is the complete code −Example Live Demousing System; using System.Text; public class Demo {    public static void Main() {       int[] arr = { 3, 4, 12 };       Console.WriteLine("Initial Array...");       // loop through the byte array       for (int i = 0; i < Buffer.ByteLength(arr); i++) {          Console.WriteLine(Buffer.GetByte(arr, i)); ... Read More

Release Cursor Memory Associated with MySQL Result in PHP

usharani
Updated on 22-Jun-2020 14:03:17

335 Views

As we know that PHP uses the msql_free_result() function to release cursor memory associated with MySQL result. To illustrate it we are having the following example −ExampleIn this example, we are writing the following PHP script that will release the memory after fetching the records from a table named ‘Tutorials_tbl’.

Merge Two Arrays Using Chash AddRange Method

Samual Sam
Updated on 22-Jun-2020 14:02:58

3K+ Views

Firstly, set two arrays −int[] arr1 = { 15, 20, 27, 56 }; int[] arr2 = { 62, 69, 76, 92 };Now create a new list and use AddRange() method to merge −var myList = new List(); myList.AddRange(arr1); myList.AddRange(arr2);After that, convert the merged collection to an array −int[] arr3 = myList.ToArray()Let us see the complete codeExample Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       int[] arr1 = { 15, 20, 27, 56 };       int[] arr2 = { 62, 69, 76, 92 };       // displaying array1     ... Read More

Fetch Data from MySQL Table Using PHP Script

varma
Updated on 22-Jun-2020 14:02:39

803 Views

If we want to fetch conditional data from MySQL table then we can write WHERE clause in SQL statement and use it with a PHP script. While writing the PHP script we can use PHP function mysql_query(). This function is used to execute the SQL command and later another PHP function mysql_fetch_array() can be used to fetch all the selected data. This function returns a row as an associative array, a numeric array, or both. This function returns FALSE if there are no more rows. To illustrate it we are having the following example −ExampleIn this example we are writing ... Read More

Copy Range of Bytes from One Array to Another in C#

karthikeya Boyini
Updated on 22-Jun-2020 14:01:56

3K+ Views

Use the Buffer.BlockCopy method to copy a range of bytes from one array to another −Set a byte array −byte[] b1 = new byte[] {22, 49}; byte[] b2 = new byte[5];Copy bytes from one array to another −Buffer.BlockCopy(b1, 0, b2, 0, 2);The following is the complete code −Example Live Demousing System; class Demo {    static void Main(){       // byte arrays       byte[] b1 = new byte[] {22, 49};       byte[] b2 = new byte[5];       // copying bytes from one to another       Buffer.BlockCopy(b1, 0, b2, 0, 2);   ... Read More

Update Existing MySQL Table Using PHP Script

Sreemaha
Updated on 22-Jun-2020 14:01:31

357 Views

We can use the SQL UPDATE command with or without the WHERE CLAUSE in the PHP function – mysql_query(). This function will execute the SQL command in a similar way it is executed at the mysql> prompt. To illustrate it we are having the following example −ExampleIn this example, we are writing a PHP script to update the field named tutorial_title for a record having turorial_id as 3.

Create MySQL View by Selecting Range of Values from Base Table

Kumar Varma
Updated on 22-Jun-2020 14:00:50

243 Views

As we know that MySQL BETWEEN operator can be used to select values from some range of values. We can use BETWEEN operator along with views to select some range of values from the base table. To understand this concept we are using the base table ‘student_info’ having the following data −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Chandigarh | Literature | | 125  | Raman   | Shimla     ... Read More

Convert Integer Array to String Array in C#

karthikeya Boyini
Updated on 22-Jun-2020 14:00:24

2K+ Views

Use the ConvertAll method to convert integer array to string array.Set an integer array −int[] intArray = new int[5]; // Integer array with 5 elements intArray[0] = 15; intArray[1] = 30; intArray[2] = 44; intArray[3] = 50; intArray[4] = 66;Now use Array.ConvertAll() method to convert integer array to string array −Array.ConvertAll(intArray, ele => ele.ToString());Let us see the complete code −Example Live Demousing System; using System.Text; public class Demo {    public static void Main() {       int[] intArray = new int[5];       // Integer array with 5 elements       intArray[0] = 15;       intArray[1] = 30;       intArray[2] = 44;       intArray[3] = 50;       intArray[4] = 66;       string[] strArray = Array.ConvertAll(intArray, ele => ele.ToString());       Console.WriteLine(string.Join("|", strArray));    } }Output15|30|44|50|66

Advertisements