Open a Plain Text File in C#

Arjun Thakur
Updated on 22-Jun-2020 12:44:26

313 Views

To open a plain text file, use the StreamReader class. The following opens a file for reading −StreamReader sr = new StreamReader("d:/new.txt")Now, display the content of the file −while ((line = sr.ReadLine()) != null) {    Console.WriteLine(line); }Here is the code −Example Live Demousing System; using System.IO; namespace FileApplication {    class Program {       static void Main(string[] args) {          try {             using (StreamReader sr = new StreamReader("d:/new.txt")) {                string line;                // ... Read More

Different Ways of Reading a File in C#

Chandu yadav
Updated on 22-Jun-2020 12:43:05

288 Views

Here, we are reading two different files −Reading text file −Example Live Demousing System; using System.IO; namespace FileApplication {    class Program {       static void Main(string[] args) {          try {             using (StreamReader sr = new StreamReader("d:/new.txt")) {                string line;                // Read and display lines from the file until                // the end of the file is reached.                while ((line ... Read More

Create MySQL Recurring Event with Specified Time Period

Arushi
Updated on 22-Jun-2020 12:40:27

374 Views

As we know that recurring event means that it will be executed after regular time of interval and expires at the specified time. To illustrate the creation of such kind of events we are using the following example in which we are creating an event which will execute after every minute and expires after one hour −mysql> CREATE EVENT testing_event10 ON SCHEDULE EVERY 1 MINUTE STARTS CURRENT_TIMESTAMP ENDS CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO INSERT INTO event_message(message, generated_at) Values('Recrring evnts', NOW()); Query OK, 0 rows affected (0.00 sec) mysql> Select * from event_message; +----+----------------+---------------------+ | ID | MESSAGE   ... Read More

Open Hidden File Using C#

George John
Updated on 22-Jun-2020 12:40:11

699 Views

To open a hidden file, first make it visible. You can do this by removing the hidden attribute set on it −FileInfo file= new FileInfo(Environment.CurrentDirectory + @"\myFile.txt"); file.Attributes &= ~FileAttributes.Hidden;Now treat it as a normal text file and open it. Read the content −using (StreamReader sr = new StreamReader("myFile.txt")) {    string line;    while ((line = sr.ReadLine()) != null) {       Console.WriteLine(line);    } }After reading, set the attribute as hidden again to hide the file −file.Attributes |= FileAttributes.Hidden;

Fetch Alternate Odd Numbered Records from MySQL Table

Rishi Rathor
Updated on 22-Jun-2020 12:39:47

997 Views

To understand this concept, we are using the data from table ‘Information’ as follows −mysql> Select * from Information; +----+---------+ | id | Name    | +----+---------+ | 1  | Gaurav  | | 2  | Ram     | | 3  | Rahul   | | 4  | Aarav   | | 5  | Aryan   | | 6  | Krishan | +----+---------+ 6 rows in set (0.00 sec)Now, the query below will fetch the alternate odd-numbered records from the above table ‘Information’ −mysql> Select id,Name from information group by id having mod(id,2) = 1; +----+--------+ | id | Name   | +----+--------+ | 1  | Gaurav | | 3  | Rahul  | | 5  | Aryan  | +----+--------+ 3 rows in set (0.09 sec)

Fetch Second Highest Salary from MySQL Table

Ramu Prasad
Updated on 22-Jun-2020 12:39:06

274 Views

To understand this concept, we are using the data from table ‘Salary’ as follows −mysql> Select * from Salary; +--------+--------+ | Name   | Salary | +--------+--------+ | Gaurav |  50000 | | Rahul  |  40000 | | Ram    |  45000 | | Raman  |  45000 | +--------+--------+ 4 rows in set (0.00 sec) mysql> Select * from salary12345 order by salary DESC limit 1 offset 1; +-------+--------+ | name  | Salary | +-------+--------+ | Raman |  45000 | +-------+--------+ 1 row in set (0.00 sec)

Conversion of ArrayList to Array in C#

Ankith Reddy
Updated on 22-Jun-2020 12:38:40

1K+ Views

To convert an ArrayList to Array, use the ToArray() method in C#.Firstly, set an ArrayList −ArrayList arrList = new ArrayList(); arrList.Add("one"); arrList.Add("two"); arrList.Add("three");Now, to convert, use the ToArray() method −arrList.ToArray(typeof(string)) as string[];Let us see the complete code −Example Live Demousing System; using System.Collections; public class Program {    public static void Main() {       ArrayList arrList = new ArrayList();       arrList.Add("one");       arrList.Add("two");       arrList.Add("three");       string[] arr = arrList.ToArray(typeof(string)) as string[];       foreach (string res in arr) {          Console.WriteLine(res);       }    } }Outputone two three

Enable and Disable a Particular MySQL Event

Sai Nath
Updated on 22-Jun-2020 12:38:29

3K+ Views

With the help of ALTER EVENT statement along with the ENABLE and DISABLE keyword, we can ENABLE and DISABLE the event. To illustrate it we are having the following example −Examplemysql> ALTER EVENT hello DISABLE; Query OK, 0 rows affected (0.00 sec)The above query will DISABLE the event named ‘Hello’ and the query below will enable it.mysql> ALTER EVENT hello ENABLE; Query OK, 0 rows affected (0.00 sec)

Class and Static Variables in C#

Arjun Thakur
Updated on 22-Jun-2020 12:38:08

8K+ Views

Static variables are used for defining constants because their values can be retrieved by invoking the class without creating an instance of it. Static variables can be initialized outside the member function or class definition. You can also initialize static variables inside the class definition.Example Live Demousing System; namespace StaticVarApplication {    class StaticVar {       public static int num;       public void count() {          num++;       }       public int getNum() {          return num;       }    }    class ... Read More

Find Employees from MySQL Table with Age Greater Than 30

Vrundesha Joshi
Updated on 22-Jun-2020 12:37:37

1K+ Views

To understand this concept, we are using the data from table ‘emp_tbl’ as follows −mysql> Select * from emp_tbl; +--------+------------+ | Name   | DOB        | +--------+------------+ | Gaurav | 1984-01-17 | | Gaurav | 1990-01-17 | | Rahul  | 1980-05-22 | | Gurdas | 1981-05-25 | | Naveen | 1991-04-25 | | Sohan  | 1987-12-26 | +--------+------------+ 6 rows in set (0.00 sec) mysql> SELECT Name, SYSDATE(), DOB, DATEDIFF(SYSDATE(), DOB)/365 AS AGE from emp_tbl WHERE(DATEDIFF(SYSDATE(), DOB)/365)>30; +--------+---------------------+------------+---------+ | Name   | SYSDATE()           | DOB        | AGE   ... Read More

Advertisements