![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use the String.Length property in C# to get the length of the string.str.LengthThe property calculates the words in the string and displays the length of the specified string, for example, the string Amit has 4 characters −string str = "Amit";ExampleThe following is the C# program to calculate the string length − Live Demousing System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { string str = "Amit"; Console.WriteLine("String: "+str); Console.WriteLine("String Length: "+str.Length); Console.ReadKey(); } } }OutputString: Amit String Length: 4
We can use SET PASSWORD statement to change the password. Before using this command, we need to have at least UPDATE privileges. Its syntax would be as follows −SyntaxSET PASSWORD FOR ‘user_name@host_name’=new_password;Here, New_password would be new password we want to set for MySQL userUser_name is the name of the current user.Host_name is the name of the host of the current user.ExampleSuppose if we want to change the password user@localhost to ‘tutorials’ then it can be done as follows −SET PASSWORD FOR ‘user@localhost’= tutorials;
We can also use ALTER USER statement along with IDENTIFIED BY clause to change MySQL user password. Its syntax would be as possible −SyntaxALTER USER user_name@host_name IDENTIFIED BY ‘new_password’Here, New_password would be new password we want to set for MySQL userUser_name is the name of a current user.Host_name is the name of the host of a current user.ExampleSuppose if we want to change the password user@localhost to ‘tutorials’ then it can be done as follows −ALTER USER user@localhost IDENTIFIED BY ‘tutorials’
System.DivideByZeroException is a class that handles errors generated from dividing a dividend with zero.ExampleLet us see an example −using System; namespace ErrorHandlingApplication { class DivNumbers { int result; DivNumbers() { result = 0; } public void division(int num1, int num2) { try { result = num1 / num2; } catch (DivideByZeroException e) { Console.WriteLine("Exception caught: {0}", e); } finally { Console.WriteLine("Result: {0}", result); } } static void Main(string[] args) { DivNumbers d = new DivNumbers(); d.division(25, 0); Console.ReadKey(); } } }OutputThe values entered here is num1/ num2 −result = num1 / num2;Above, if num2 is set to 0, then the DivideByZeroException is caught since we have handled exception above.
We need to use nested SUBSTRING_INDEX() function for getting the substring as output which is between two same delimiters in a string. For example, from the string ‘www.tutorialspoint.com’, we want the substring ‘tutorialspoint’, which is in between two same delimiters ‘.’ as output then SUBSTRING_INDEX() function can be used in nested form as follows −mysql> Select SUBSTRING_INDEX(SUBSTRING_INDEX('www.tutorialspoint.com','.',2),'.',-1)AS 'Nested SUBSTRING_INDEX'; +------------------------+ | Nested SUBSTRING_INDEX | +------------------------+ | tutorialspoint | +------------------------+ 1 row in set (0.02 sec)
To concatenate two strings, use the String.Concat method.Let’s say you want to concatenate two strings in C#, str1 and str2, then add it as arguments in the Concat method −string str3 = string.Concat(str1, str2);ExampleThe following is the example − Live Demousing System; class Program { static void Main() { string str1 = "Brad"; string str2 = "Pitt"; // Concat strings string str3 = string.Concat(str1, str2); Console.WriteLine(str3); } }OutputBradPitt
Assign value to a variable using the assignment operator in C# −The following are the assignment operators in C# −OperatorDescriptionExample=Simple assignment operator, Assigns values from right side operands to left side operandC = A + B assigns value of A + B into C+=Add AND assignment operator, It adds right operand to the left operand and assign the result to left operandC += A is equivalent to C = C + A-=Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operandC -= A is equivalent to C = C – A*=Multiply ... Read More
To define a custom method in C#, use the following syntax − (Parameter List) { Method Body }The following are the various elements of a method −Access Specifier − This determines the visibility of a variable or a method from another class.Return type − A method may return a value. The return type is the data type of the value the method returns. If the method is not returning any values, then the return type is void.Method name − Method name is a unique identifier and it is case sensitive. It cannot be same as any other identifier declared ... Read More
You can store any type of value in the dynamic data type variable. Type checking for these types of variables takes place at run-time. C# 4.0 introduced the dynamic type that avoids compile time type checking.The following is the syntax for declaring a dynamic type −dynamic = value;Dynamic types are similar to object types except that type checking for object type variables takes place at compile time, whereas that for the dynamic type variables takes place at run time.Let us see an example −dynamic a = 25;To get the type of dynamic variable −Exampleusing System; namespace Demo { ... Read More
C# does not have global variables and the scope resolution operator used in C++ for global variables is related to namespaces. It is called global namespace alias.If you have a type that shares an identifier in a different namespace, then to identify them using the scope resolution operator.For example, to reference System.Console class, use the global namespace alias with the scope resolution operator −global::System.ConsoleLet us now see an example −Example Live Demousing myAlias = System.Collections; namespace Program { class Demo { static void Main() { myAlias::Hashtable h = new myAlias::Hashtable(); ... Read More
To Continue Learning Please Login