Truncate a File in C#

Ankith Reddy
Updated on 22-Jun-2020 12:34:29

1K+ Views

To truncate a file in C#, use the FileStream.SetLength method.Here is the syntax −public override void SetLength (long value);Here, int64 = Length of the streamValue < current LengthIf the value is less than the current length of the stream: The stream is truncated. If the current position is greater than the new length, the current position is moved to the last byte of the stream.Value > current LengthThe stream is expanded, and the current position remains the same. If the stream is expanded, the contents of the stream between the old and the new length are undefined.The following is an ... Read More

Modify an Existing MySQL Event

Samual Sam
Updated on 22-Jun-2020 12:34:23

558 Views

With the help of ALTER EVENT statement, we can modify an existing MySQL event. We can change the various attributes of an event. ALTER EVENT has the following syntax −   ALTER EVENT event_name     ON SCHEDULE schedule ON COMPLETION [NOT] PRESERVE   RENAME TO new_event_name     ENABLE | DISABLE            DO        event_bodyTo understand it we are illustrating the example as below −ExampleSuppose we have an event as follows −mysql> Create event hello ON SCHEDULE EVERY 1 Minute DO INSERT INTO event_messages(message, generated_at) Values ('Alter event testing', NOW()); Query OK, 0 rows ... Read More

Declaring an Array in C#

karthikeya Boyini
Updated on 22-Jun-2020 12:33:45

115 Views

Declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array.The following is a declaration and it will not create an array −int[] id;The following create an array of integers. The array is a reference type, so you need to use the new keyword to create an instance of the array −Int[] id = new int[5] {};Let us see an example −Example Live Demousing System; namespace ArrayApplication {    public class MyArray {       public static void Main(string[] args) {          int ... Read More

Rename an Existing MySQL Event

Paul Richard
Updated on 22-Jun-2020 12:33:25

197 Views

With the help of ALTER EVENT statement along with the RENAME keyword, we can RENAME an existing event. To illustrate it we are having the following example in which we are renaming the event ‘Hello’ to ‘Hello_renamed’ −Examplemysql> ALTER EVENT Hello RENAME TO Hello_renamed; Query OK, 0 rows affected (0.00 sec)To confirm that event has been renamed we can try to delete the event with the old name, MySQL will throw an error as follows −mysql> DROP EVENT hello; ERROR 1539 (HY000): Unknown event 'hello'

Make a C# Program Sleep for X Milliseconds

Samual Sam
Updated on 22-Jun-2020 12:32:53

1K+ Views

To make a C# program sleep for x milliseconds, use the Thread.Sleep() method.To set it for 1000 milliseconds −Thread.Sleep(1000);The following is the code showing how to set a counter for the thread and set it to sleep for 1000 milliseconds on every iteration of for loop −Example Live Demousing System; using System.Threading; namespace MultithreadingApplication {    public class ThreadCreationProgram {       public static void CallToChildThread() {          try {             Console.WriteLine("Child thread starts");             for (int counter = 0; counter

Schedule Different Types of MySQL Events

Ankith Reddy
Updated on 22-Jun-2020 12:32:13

159 Views

Basically, there are two kinds of events for which we need to specify the schedule −One-time eventOne-time event means it will be executed only once on a particular schedule. If we want to create a one-time event then we need to put the following syntax after ON SCHEDULE clause −AT Timestamp[+INTERVAL]Recurring eventsRecurring event means that it will be executed after regular time of interval. If we want to create a recurring event then we need to put the following syntax after ON SCHEDULE clause −EVERY interval STARTS timestamp [+INTERVAL] ENDS timestamp [+INTERVAL]

GROUP BY Clause Without Aggregate Function

Krantik Chavan
Updated on 22-Jun-2020 12:31:12

6K+ Views

When we use GROUP BY clause in the SELECT statement without using aggregate functions then it would behave like DISTINCT clause. For example, we have the following table −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Chandigarh | Literature | | 125  | Raman   | Shimla     | Computers  | | 130  | Ram     | Jhansi     | Computers  | | 132  | Shyam   | Chandigarh ... Read More

Start MySQL Event Scheduler

Vikyath Ram
Updated on 22-Jun-2020 12:30:22

947 Views

Actually, MySQL event scheduler is a process that runs in the background and constantly looks for the events to execute. But before we create or schedule an event we just have to start the scheduler. It can start with the help of the following statement −mysql> SET GLOBAL event_scheduler = ON; Query OK, 0 rows affected (0.07 sec)Now with the help of the following statement,  we can check its status in MySQL process list −mysql> SHOW PROCESSLIST\G *************************** 1. row ***************************      Id: 3    User: root    Host: localhost:49500      db: query Command: Query    Time: 0   State: ... Read More

Empty a Chash List in Java

Giri Raju
Updated on 22-Jun-2020 12:29:44

14K+ Views

To empty a C# list, use the Clear() method.Firstly, set a list and add elements −List myList = new List() {    "one",    "two",    "three",    "four",    "five",    "six" };Now, let us empty the list −myList.Clear();Example Live Demousing System; using System.Collections.Generic; public class Program {    public static void Main() {       List myList = new List() {          "one",          "two",          "three",          "four",          "five",          "six"       };       ... Read More

Randomize Set of Rows or Values in MySQL Result Set

Daniol Thomas
Updated on 22-Jun-2020 12:29:33

166 Views

With the help of RAND() function used along with the ORDER BY clause, the set of rows or values can be randomized in the result set. To understand it considers a table ‘Employee’ having the following records −mysql> Select * from employee; +----+--------+--------+ | ID | Name   | Salary | +----+--------+--------+ | 1  | Gaurav | 50000  | | 2  | Rahul  | 20000  | | 3  | Advik  | 25000  | | 4  | Aarav  | 65000  | | 5  | Ram    | 20000  | | 6  | Mohan  | 30000  | | 7  | Aryan  | ... Read More

Advertisements