
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

304 Views
The Array.Clear class in C# clears i.e.zeros out all elements.In the below example, we have first considered an array with 3 elements.int[] arr = new int[] { 11, 40, 20};Now we have used the Array.clear method to zero out all the arrays.Array.Clear(arr, 0, arr.Length);Let us see an example of Array.clear method in c#.Example Live Demousing System; class Program { static void Main() { int[] arr = new int[] {11, 40, 20}; Console.WriteLine("Array (Old):"); foreach (int val in arr) { Console.WriteLine(val); } ... Read More

335 Views
A conditional operator is represented by the symbol '?:' The first operand is the evaluating expression. It has right to left associativity.The syntax for conditional operator.expression ? expression : expressionThe conditional operator works as follows −The first operand is implicitly converted to bool.If the first operand evaluates to true, the second operand is evaluated.If the first operand evaluates to false, the third operand is evaluated.Remember, only one of the last two operands is evaluated in a conditional expression.Example Live Demousing System; namespace Demo { class Program { static void Main(string[] args) { int ... Read More

249 Views
The following is the unsorted array.int[] list = {98, 23, 97, 36, 77};Now first use the Sort() method to sort the array.Array.Reverse(list);Use the Reverse() method that would eventually give you a sorted array in descending order.Array.Reverse(list);You can try to run the following code to to sort one dimensional array in descending order.Example Live Demousing System; namespace Demo { public class MyApplication { public static void Main(string[] args) { int[] list = {98, 23, 97, 36, 77}; Console.WriteLine("Original Unsorted List"); foreach (int i in list) { ... Read More

325 Views
With StringBuilder, you can expand the number of characters in the string. String cannot be changed once it is created, but StringBuildercan be expanded. It does not create a new object in the memory.Initialize StringBuilder.StringBuilder str = new StringBuilder();Let us see an example to learn how to work with StringBuilder in C#.Example Live Demousing System; using System.Text; public class Program { public static void Main() { StringBuilder str = new StringBuilder("Web World!!",30); str.Replace("World", "Arena"); Console.WriteLine(str); } }OutputWeb Arena!!Above the Replace() method of StringBuilder is used to to replace a string in C#.

178 Views
For the Boolean type, the bool keyword is used and is an alias of System.Boolean.It is used to declare variables to store the Boolean values, true and false.Let us see an example to learn how to use bool in C#.Exampleusing System; public class Demo { static void Main() { bool val = true; int d = DateTime.Now.DayOfYear; val = (d % 2 == 0); if (val) { Console.WriteLine("days: even number"); } else { Console.WriteLine("days:odd number"); } } }

282 Views
A class can be derived from more than one class or interface, which means that it can inherit data and functions from multiple base classes or interfaces.For example, Vehicle Base class with the following Derived Classes.Truck Bus MotobikeThe derived class inherits the base class member variables and member methods.In the same way, the derived class for Shape class can be Rectangle as in the following example.Example Live Demousing System; namespace Program { class Shape { public void setWidth(int w) { width = w; } public void setHeight(int ... Read More

2K+ Views
To sort an ArrayList in C#, use the Sort() method.The following is the ArrayList.ArrayList arr = new ArrayList(); arr.Add(32); arr.Add(12); arr.Add(55); arr.Add(8); arr.Add(13);Now the Sort() method is used to sort the ArrayList.arr.Sort();You can try to run the following code to sort an ArrayList in C#.Example Live Demousing System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { ArrayList arr = new ArrayList(); arr.Add(32); arr.Add(12); arr.Add(55); arr.Add(8); arr.Add(13); ... Read More

112 Views
Array can be initialized in more than one ways in C#. Let us see some example.Method OneUsing size of array.int [] marks = new int[5] { 99, 98, 92, 97, 95};Method TwoBy omitting the size.int [] marks = new int[] { 99, 98, 92, 97, 95};Method ThreeInitializing at the time of declaration.int [] marks = { 99, 98, 92, 97, 95};Let us see one of the ways to initialize arrays in C#.Example Live Demousing System; namespace Demo { class MyArray { static void Main(string[] args) { int [] n = new int[10]; /* ... Read More

1K+ Views
The List is a collection in C# and is a generic collection. The add and remove methods are used in C# lists for adding and removing elements.Let us see how to use Add() method in C#.Example Live Demousing System; using System.Collections.Generic; class Program { static void Main() { List sports = new List(); sports.Add("Football"); sports.Add("Tennis"); sports.Add("Soccer"); foreach (string s in sports) { Console.WriteLine(s); } } }OutputFootball Tennis SoccerLet us see how to use Remove() method in C#.Example Live ... Read More

877 Views
Properties are an extension of fields and are accessed using the same syntax. They use accessors through which the values of the private fields can be read, written or manipulated.The accessor of a property contains the executable statements that helps in getting (reading or computing) or setting (writing) the property.Let us see an example of properties in C#.ExampleDeclare a code property of type string.public string Code { get { return code; } set { code = value; } }In the same way, declare Age property of type as in the ... Read More