The easiest way to convert an integer to a string in C# is using the ToString() method.Let us see an example −int a = 100; string str = a.ToString();Another way is to use Convert.ToString();b = 50; string str2 = Convert.ToString(b); Console.WriteLine(str2);The following is the example showing the different ways to convert integer to string.Example Live Demousing System; class Program { static void Main() { int a, b, c; a = 10; string str = a.ToString(); Console.WriteLine(str); b = 50; string str2 = Convert.ToString(b); Console.WriteLine(str2); c = 100; string str3 = string.Format("{0}", c); Console.WriteLine(str3); } }Output10 50 100
The Object class is the base class of all the classes in C#. It has the following methods on C#.Sr.NoMethod & Description1Equals(Object)Determines whether the specified object is equal to the current object.2Equals(Object, Object, Determines whether the specified object instances are considered equal.3Finalize()Allows an object to try to free resources4GetHashCode()default hash function.5GetType()Type of the current instance.6MemberwiseClone()shallow copy of the current Object.7ReferenceEquals(Object, Object)Determines whether the specified Object instances are the same instance.8ToString()Returns a string that represents the current object.Let us see an example how to create an object of a class in C#.Example Live Demousing System; namespace MyApplication { class Demo { ... Read More
Suppose if we declare a variable inside a BEGIN/END block then the scope of this variable would be in this particular block. We can also declare a variable with the same name inside another BEGIN/END block which will be totally legal but its scope would be inside its BEGIN/END block. It can be understood with the help of the following example in which we are creating a procedure to show the scope of the variables −Examplemysql> Create Procedure Scope_variables() -> BEGIN -> DECLARE A Varchar(5) Default 'outer'; -> BEGIN -> DECLARE A ... Read More
Actually, MySQL preserves the environment at the time the stored procedure is created. It can be understood with the help of following the example in which we are using two bars for concatenating strings. This is only legal while SQL mode is ansi. But if we change the SQL mode to non-ansi, the procedure still works as if the original setting is still true.Examplemysql> Set sql_mode = 'ansi'// Query OK, 0 rows affected, 1 warning (0.14 sec) mysql> Create Procedure Con_string() -> SELECT 'a'||'b'// Query OK, 0 rows affected (0.12 sec) mysql> Call Con_string (); +----------+ | ... Read More
Declaration means that variable is only declared and memory is allocated, but no value is set.However, definition means the variables has been initialized.The same works for variables, arrays, collections, etc.VariablesDeclaring a variable.int x;Let’s define and assign a value.x = 10; ArraysDeclaring an array.int [] n // declaring int n= new int[10]; // initializingLet’s assign a value.n[0] = 100; n[1] = 200
TrimA string method that removes all the leading and trailing whitespaces in a string.For example, the string “jack sparrow“ would be returned as the following without leading and whitespaces using trim().jack sparrowThe following is an example −Example Live Demousing System; namespace Demo { class Program { static void Main(string[] args) { string str = " Amit "; Console.WriteLine(str); // trim Console.WriteLine("After removing leading and trailing whitespace..."); string res = str.Trim(); Console.WriteLine(res); ... 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.The Object Type is the ultimate base class for all data types in C# Common Type System (CTS). The object is an alias for System. Object class. The object types can be assigned values of any other types, value types, reference types, predefined or user-defined types.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 runtime.Example of ... Read More
Prefix OperatorThe increment operator ++ if used as prefix on a variable, the value of variable gets incremented by 1. After that the value is returned unlike Postfix operator. It is called Prefix increment operator. In the same way the prefix decrement operator works but it decrements by 1.For example, an example of prefix operator −++a;The following is an example demonstrating Prefix increment operator −Example Live Demousing System; class Program { static void Main() { int a, b; a = 50; Console.WriteLine(++a); b = a; ... Read More
Some of the key keywords in C#, include.SealedParamsInternalthisabstractSealedWhen you use sealed modifiers in C# on a method, then the method loses its capabilities of overriding. The sealed method should be part of a derived class and the method must be an overridden method.ParamsWhile declaring a method, you are not sure of the number of arguments passed as a parameter, then use params. C# param arrays can let you know about this.InternalInternal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly. Any member with internal access specifier can ... Read More
C# has a lot of inbuilt Data Structures. Here are two of them −ListGeneric List is a generic collection and the ArrayList is a non-generic collection. The size can be dynamicallyincreased using List, unlike Arrays.Let us see an example.We have set the List first −List myList = new List()ArrayListIt represents ordered collection of an object that can be indexed individually.Set an ArrayList as −ArrayList arr = new ArrayList(); arr.Add(67); arr.Add(34); arr.Add(99); arr.Add(45);
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP