- Trending Categories
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
Found 2628 Articles for Csharp
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
3K+ Views
Class instances are objects. Like any other object-oriented language, C# also has object and classes. Objest are real-world entities and instance of a class. Access the members of the class using an object.To access the class members, you use the dot (.) operator after the object name. The dot operator links the name of an object with the name of a member for example, Box Box1 = new Box();Above you can see Box1 is our object. We will use it to access the members −Box1.height = 7.0;You can also use it to call member functions −Box1.getVolume();The following is an example ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
166 Views
A class constructor is a special member function of a class that is executed whenever we create new objects of that class. A default constructor does not have any parameter.The following is an example showing how to work with default constructor in C# −Example Live Demousing System; namespace LineApplication { class Line { private double length; // Length of a line public Line(double len) { //Parameterized constructor Console.WriteLine("Object is being created, length = {0}", len); length = len; } ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
92 Views
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
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
684 Views
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
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
3K+ Views
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.
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
10K+ 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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ 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
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
3K+ 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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
515 Views
A variable is a name given to a storage area that our programs can manipulate. Each variable in C# has a specific type, which determines the size and layout of the variable's memory the range of values that can be stored within that memory and the set of operations that can be applied to the variable.To assign values to a variable, add the value after the equal operator −int a = 10;Let us see how to assign values to a variable and print itExample Live Demousing System; namespace Demo { class Program { static ... Read More