Foreach in C++C++ 11 introduced foreach loop to traverse over each element. Here is an example −Example Live Demo#include using namespace std; int main() { int myArr[] = { 99, 15, 67 }; // foreach loop for (int ele : myArr) cout
As we know that views are definitions built on the top of other tables or views and stored in the database. Followings are benefits of using MySQL views as compared to selecting data directly from MySQL base tablesSimplify data accessThe use of views simplifies the data access because of the following reasons −A view can be used to perform a calculation and display its result. For example, a view definition that invokes aggregate functions can be used to display a summary.With the help of views, we can select a restricted set of rows by means of an appropriate WHERE clause ... Read More
Firstly, set the list −List myList = new List () { 5, 10, 7 };Now, set the value of a variable to 1 that would help us in multiplying −int prod = 1;Loop through and get the product −foreach(int i in myList) { prod = prod*i; }The following is the code −Example Live Demousing System; using System.Collections.Generic; public class Program { public static void Main() { List myList = new List() { 5, 10, 7 }; Console.WriteLine("List: "); foreach(int i in myList) { Console.WriteLine(i); } int prod = 1; foreach(int i in myList) { prod = prod*i; } Console.WriteLine("Product: {0}",prod); } }OutputList: 5 10 7 Product: 350
MySQL VersionAs we know that MySQL 5 introduced views, hence, first of all, we need to check for the version of MySQL before starting writing and using stored procedures. It can be done with the following query −mysql> Select VERSION(); +-----------+ | VERSION() | +-----------+ | 5.7.20 | +-----------+ 1 row in set (0.10 sec)Privileges for current userActually CREATE VIEW statement requires the CREATE VIEW privilege. Privileges for the current user can be checked with the following query −mysql> SHOW PRIVILEGESSelecting a databaseBefore creating a view we must have to select a database from the available databases. It can ... Read More
To check for all vowels, firstly set the condition to check −string res = str.Where(chk =< "aeiouAEIOU".Contains(chk)).Distinct();Above, we have used the string −string str = "the quick brown fox jumps over the lazy dog";Now, using the Any() method checks whether the string has any vowels or not −if(!res.Any()) Console.WriteLine("No vowels!");Loop through the string to get the vowels −Example Live Demousing System; using System.Linq; public class Program { public static void Main() { string str = "the quick brown fox jumps over the lazy dog"; var res = str.Where(chk =< "aeiouAEIOU".Contains(chk)).Distinct(); ... Read More
To merge two sorted arrays into a list, firstly set two sorted arrays −int[] array1 = { 1, 2 }; int[] array2 = { 3, 4 };Add it to a list and merge −var list = new List(); for (int i = 0; i < array1.Length; i++) { list.Add(array1[i]); list.Add(array2[i]); }Now, use the ToArray() method to convert back into an array as shown below −Example Live Demousing System; using System.Collections.Generic; public class Program { public static void Main() { int[] array1 = { 56, 70, 77}; int[] array2 = ... Read More
In spite of various benefits of using views there are following limitations on using MySQL views − Can’t create an index of views − In MySQL, we cannot create an index on views. It is because indexes are not utilized when we query data against the views. MySQL invalidates the view − Suppose, if we drop or rename tables to which a view references, rather than issuing an error MySQL invalidate the view. We can use the CHECK TABLE statement to check whether the view is valid or not. MySQL views cannot be updateable in some situations − Actually, the simple view can ... Read More
To get the binary of Decimal, using recursion, firstly set the decimal number −int dec = 30;Now pass the value to a function −public int displayBinary(int dec) { }Now, check the condition until the decimal value is 0 and using recursion get the mod 2 of the decimal num as shown below. The recursive call will call the function again with the dec/2 value −public int displayBinary(int dec) { int res; if (dec != 0) { res = (dec % 2) + 10 * displayBinary(dec / 2); Console.Write(res); return ... Read More
Firstly, set a tuple −Tuple t = Tuple.Create(99,53);Now, convert the tuple to an array −int[] arr = new int[]{t.Item1, t.Item2};The following is the code to convert a tuple into an array −Example Live Demousing System; using System.Linq; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) { Tuple t = Tuple.Create(99,53); int[] arr = new int[]{t.Item1, t.Item2}; foreach (int val in arr) { Console.WriteLine(val); } } } }Output99 53
friend in C#A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.A friend can be a function, function template, or member function, or a class or class template, in which case the entire class and all of its members are friends.C++ equivalent of friend in C#The closest equivalent is to create a nested class that will access the outer class private members.Here, the inner class can ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP