Implement Stack with Push and Pop Operations in C#

Samual Sam
Updated on 20-Jun-2020 10:59:24

764 Views

Set stack with Push operation to add elements to the Stack −Stack st = new Stack(); st.Push('A'); st.Push('M'); st.Push('G'); st.Push('W');To Pop elements from the stack, use Pop() method −st.Pop();st.Pop();The following is an example to implement a stack with Push and Pop operations −Example Live Demousing System; using System.Collections; namespace CollectionsApplication {    class Program {       static void Main(string[] args) {          Stack st = new Stack();          st.Push('A');          st.Push('M');          st.Push('G');          st.Push('W');          Console.WriteLine("Current ... Read More

Assign a Reference to a Variable in C#

Ankith Reddy
Updated on 20-Jun-2020 10:57:25

6K+ Views

To assign reference to a variable, use the ref keyword. A reference parameter is a reference to a memory location of a variable. When you pass parameters by reference, unlike value parameters, a new storage location is not created for these parameters. Declare the reference parameters using the ref keyword.Let us see an example −Here, we are swapping two values using the ref keyword −Example Live Demousing System; namespace Demo {    class Program {       public void swap(ref int x, ref int y) {          int temp;          temp = ... Read More

Similarity Between Prepared Statements and MySQL User Variables

seetha
Updated on 20-Jun-2020 10:57:22

176 Views

As we know that MySQL user variables are specific to client connection within which they are used and exist only for the duration of that connection. When a connection ends, all its user variables are lost. Similarly, the prepared statements also exist only for the duration of the session in which it is created and it is visible to the session in which it is created. When a session ends, all the prepared statements for that session are discarded.Another similarity is that prepared statements are also not case-sensitive like MySQL user variables. For example, stmt11 and STMT11 both are same ... Read More

Prepare Statement with Same Name Without Deallocating in Java

Prabhas
Updated on 20-Jun-2020 10:56:55

134 Views

Actually, in MySQL, we can prepare a statement with the same name without de-allocating the earlier one because MySQL automatically drops the prepared statements when they are redefined or when we close the connection to the server. In other words, we can say that we can use the same name for prepared statements without de-allocating them explicitly. But, to free the memory on the server side we must have to de-allocate them. It can be done with the help of DEALLOCATE statement as follows −DEALLOCATE PREPARE statement;Here statement is the name of the prepared statements.DROP PREPARE statements is the synonym ... Read More

SQL Statements for Preparing Statements

Priya Pallavi
Updated on 20-Jun-2020 10:56:22

148 Views

Actually, it is not possible to prepare all SQL statements because MySQL only allows the following kinds of SQL statements that can be prepared:SELECT statementsExamplemysql> PREPARE stmt FROM 'SELECT tender_value from Tender WHERE Companyname = ?'; Query OK, 0 rows affected (0.09 sec) Statement prepared mysql> SET @A = 'Singla Group.'; Query OK, 0 rows affected (0.00 sec) mysql> EXECUTE stmt using @A; +--------------+ | tender_value | +--------------+ |   220.255997 | +--------------+ 1 row in set (0.07 sec) mysql> DEALLOCATE PREPARE stmt; Query OK, 0 rows affected (0.00 sec)INSERT, REPLACE, UPDATE and DELETEstatements that modify the ... Read More

MySQL INSTR and LIKE Operator Similarities

Lakshmi Srinivas
Updated on 20-Jun-2020 10:54:47

794 Views

We can use both INSTR() function and LIKE operator to search or match a particular pattern and they return same result. It can be demonstrated from the following example of ‘Student’ table.ExampleSuppose we want to search name, which contains ‘av’ in it, from ‘Student’ table. We can use INSTR() function as follows −mysql> Select Name from student where INSTR(name, 'av') > 0; +--------+ | Name   | +--------+ | Gaurav | | Aarav  | | Gaurav | +--------+ 3 rows in set (0.00 sec)Now, for the same kind of search we can use LIKE operator as follows −mysql> Select Name ... Read More

Create Table and Insert Values Using Prepare Statements

V Jyothi
Updated on 20-Jun-2020 10:54:07

212 Views

It can be understood with the help of following the example in which we have created the table named ‘Student’ by using prepared statement −mysql> PREPARE stmt3 FROM 'CREATE TABLE Student(Id INT, Name Varchar(20))'; Query OK, 0 rows affected (0.00 sec) Statement prepared mysql> EXECUTE stmt3; Query OK, 0 rows affected (0.73 sec) mysql> DEALLOCATE PREPARE stmt3; Query OK, 0 rows affected (0.00 sec)Now, with the help of following queries using prepared statements, we can insert the valuesin table ‘Student’ −mysql> PREPARE stmt7 FROM 'INSERT INTO Student(Id, Name) values(?, ?)'; Query OK, 0 rows affected (0.00 sec) Statement ... Read More

Update a Table Using Prepare Statements

Sravani S
Updated on 20-Jun-2020 10:53:26

180 Views

It can be understood with the help of following the example in which we have updated the table named ‘Student’, having the following data, by using prepared statement −mysql> Select * from Student; +------+-------+ | Id   | Name  | +------+-------+ | 1    | Ram   | | 2    | Shyam | | 3    | Mohan | +------+-------+ 3 rows in set (0.00 sec) mysql> PREPARE stmt11 FROM 'UPDATE Student SET Name = ? WHERE Id = ?'; Query OK, 0 rows affected (0.03 sec) Statement prepared mysql> SET @A = 'Sohan', @B = 3; ... Read More

Cloning in C#

karthikeya Boyini
Updated on 20-Jun-2020 10:52:59

402 Views

Cloning in C# is useful if you want to clone an array. The Clone() method in C# is used to create a similar copy of the array. C# has the Clone method and ICloneable interface.Let us see an example to clone an array using the Clone() method −Example Live Demousing System; class Program {    static void Main() {       string[] arr = { "one", "two", "three", "four", "five" };       string[] arrCloned = arr.Clone() as string[];       Console.WriteLine(string.Join(", ", arr));       Console.WriteLine(string.Join(", ", arrCloned));       Console.WriteLine();    } ... Read More

Use REPLACE Function with Column Data in MySQL Table

Fendadis John
Updated on 20-Jun-2020 10:52:56

226 Views

For using it with column’s data we need to provide column name as the argument of REPLACE() function. It can be demonstrated by using ‘Student’ table data as follows −Examplemysql> Select Id, Name, Subject, REPLACE(Subject, 's', ' Science') from Student WHERE Subject = 'Computers'; +------+--------+-----------+-----------------------------------+ | Id   | Name   | Subject   | REPLACE(Subject, 's', ' Science') | +------+--------+-----------+-----------------------------------+ | 1    | Gaurav | Computers | Computer Science                  | | 20   | Gaurav | Computers | Computer Science                  | +------+--------+-----------+-----------------------------------+ 2 rows in set (0.00 sec)

Advertisements