Buffer SetByte Example in C#

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

315 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

310 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

792 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

343 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.

Array BinarySearch Method in C#

Samual Sam
Updated on 22-Jun-2020 14:01:25

134 Views

Get the location of array elements using the BinarySearch method.Set a string array −string[] str = { "a", "m", "i", "t"};Now get the location of character ‘t’ using Array.BinarySearch −Array.BinarySearch(str, "t");Here is the complete code −Example Live Demousing System; using System.Text; public class Demo {    public static void Main() {       string[] str = { "a", "m", "i", "t"};       // Using BinarySearch method to get location of character 't'       int res = Array.BinarySearch(str, "t");       // displaying the location       Console.WriteLine("Index : "+res);    } }OutputIndex : 3

Create MySQL View by Selecting Range of Values from Base Table

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

228 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

Check If a Value Is in an Array in C#

Samual Sam
Updated on 22-Jun-2020 13:59:58

1K+ Views

Use the Array.Exists method to check if a value is in an array or not.Set a string array −string[] strArray = new string[] {"keyboard", "screen", "mouse", "charger" };Let’s say you need to find the value “keyboard” in the array. For that, use Array.Exists() −Array.Exists(strArray, ele => ele == "keyboard");It returns a true value if element exists as shown below −Example Live Demousing System; using System.Text; public class Demo {    public static void Main() {       string[] strArray = new string[] {"keyboard", "screen", "mouse", "charger" };       bool res1 = Array.Exists(strArray, ele => ele == "harddisk");   ... Read More

Advertisements