
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2587 Articles for Csharp

12K+ Views
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

3K+ Views
To call a method, use the name of the method after the object name, for example, −obj1. Display();Let’s say the class name is ApplicationOne, so to call the method −ApplicationOne one = new ApplicationOne(); //calling the displayMax method ret = one.displayMax(a, b);The following is the example showing how to call a method in C# −Example Live Demousing System; namespace Demp { class ApplicationOne { public int displayMax(int num1, int num2) { /* local variable declaration */ int result; if (num1 > num2) ... Read More

2K+ Views
The null coalescing operator is used with the nullable value types and reference types. It is used for converting an operand to the type of another nullable (or not) value type operand, where an implicit conversion is possible.If the value of the first operand is null, then the operator returns the value of the second operand, otherwise, it returns the value of the first operand.The following is an example −Example Live Demousing System; namespace Demo { class Program { static void Main(string[] args) { double? num1 = null; ... Read More

4K+ Views
To set multiple values to same variable, use arrays in C#. Let’s say instead of taking 5 variables, set these 5 variables using arrays in a single variable.The following is an example to set three values to a single variable with a string array −string[] arr = new string[3];Let us now initialize it −string[] arr = new string[3] {"one", "two", "three"};The following is the complete example −Example Live Demousing System; public class Demo { static void Main(string[] args) { string[] arr = new string[3] {"one", "two", "three"}; for (int i = ... Read More

1K+ Views
Let’s say the string is −Welcome User, Kindly wait for the image to loadFor multiline String Literal, firstly set it like the following statement using@ prefix −string str = @"Welcome User, Kindly wait for the image to load";Now let us display the result. The string is a multi-line string now −Example Live Demousing System; namespace Demo { class Program { static void Main(string[] args) { string str = @"Welcome User, Kindly wait for the image to load"; Console.WriteLine(str); } } }OutputWelcome User, Kindly wait for the image to load

356 Views
C# allows multidimensional arrays. It includes an array with more than one dimension. Declare a 2-dimensional array of strings as −string [, ] names;A 2-dimensional array can be thought of as a table, which has x number of rows and y number of columns.Multidimensional arrays may be initialized by specifying bracketed values for each row. The following array is with 4 rows and each row has 4 columns.int [, ] a = new int [4, 4] { {0, 1, 2, 3} , /* initializers for row indexed by 0 */ {4, 5, 6, 7} , /* initializers for row indexed ... Read More

242 Views
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

252 Views
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

1K+ Views
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

141 Views
The sort a list in C#, use the Sort() method.Let us first create a list −List myList = new List();Now add elements −myList.Add("Audi"); myList.Add("BMW"); myList.Add("Chevrolet"); myList.Add("Hyundai");Use the Sort() method to sort the list −myList.Sort();The following is an example showing how to sort a list in C# −Example Live Demousing System; using System.Collections.Generic; class Demo { static void Main() { List myList = new List(); myList.Add("Audi"); myList.Add("BMW"); myList.Add("Chevrolet"); myList.Add("Hyundai"); myList.Sort(); foreach (string value in myList) { ... Read More