- 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 2749 Articles for Csharp

834 Views
The abstract class includes abstract and non-abstract methods. You cannot instantiate an abstract class.The sealed class prevents inheritance and you cannot use it as a base class.Abstract ClassesTo declare an abstract class, you need to place the keyword abstract before the class definition. An example of class members in an abstract class can be the following that defines an abstract method −public abstract class Vehicle { public abstract void display(); }The abstract method definition is followed by a semi-colon since it has no implementation.Sealed ClassesTo declare a sealed class, you need to place the keyword sealed before the class definition. ... Read More

266 Views
Exceptions are a problem that arises when a program executed. The following keyword handles exceptions in C#:tryA try block identifies a block of code for which particular exceptions is activated.CatchThe catch keyword indicates the catching of an exception.finallyExecute a given set of statements, whether an exception is thrown or not thrown.throwAn exception is thrown when a problem shows up in a program.ExampleLet us see an example to handle the error in a C# program −Live Demousing System; namespace MyErrorHandlingApplication { class DivNumbers { int result; DivNumbers() { result = ... Read More

210 Views
To add and concatenate strings in C#, use the string. Concat method. The plus operator can also be used for the same purpose of concatenation.Plus Operatorstring str2 = "Hanks" + str1;ExampleLet us see an example of + operator to concatenate strings −Live Demousing System; class Program { static void Main() { string str1 = "Tom"; // concatenation string str2 = "Hanks" + str1; Console.WriteLine(str2); } }OutputHanksTomString.concatstring str2 = string.Concat("Hanks", str1);ExampleLet us see an example of string.concat to concatenate strings in C# −Live Demousing ... Read More

483 Views
The abstract keyword in C# is used for abstract classes. An abstract class in C# includes abstract and nonabstract methods. You cannot instantiate an abstract class.Example of an abstract class Vehicle and abstract method display() −public abstract class Vehicle { public abstract void display(); }The abstract class has derived classes: Bus, Car, and Motorcycle. The following is an implementation of the Car derived class −public class Car : Vehicle { public override void display() { Console.WriteLine("Car"); } }ExampleThe following is an example of abstract classes in C# −Live Demousing System; public abstract class Vehicle ... Read More

200 Views
An attribute is a declarative tag that is used to convey information to runtime about the behaviors of various elements like classes, methods, structures, enumerators, assemblies etc. in your program. To set an attribute −[attribute(positional_parameters, name_parameter = value, ...)] ElementHere, the name of the attribute and values come inside [ ] positional parameters allow you to specify information.ExampleThe following is an example to access attribute and methods in C# −Live Demo#define DEBUG using System; using System.Diagnostics; public class Demo { [Conditional("DEBUG")] public static void Message(string str) { Console.WriteLine(str); } } class Test { static ... Read More

612 Views
Yes, arrays zero indexed in C#. Let us see how −If the array is empty, it has zero elements and has length 0.If the array has one element in 0 indexes, then it has length 1.If the array has two elements in 0 and 1 indexes, then it has length 2.If the array has three elements in 0, 1 and 2 indexes, then it has length 3.The following states that an array in C# begins with index 0 −/* begin from index 0 */ for ( i = 0; i < 5; i++ ) { n[ i ] = ... Read More

1K+ Views
Assert statements are an effective way to catch program logic errors at runtime. It has two arguments −A boolean expression for a true condition, andWhat to display in case of false.Assertions are useful in large and complex programs to quickly flush out errors that generally arise when the code is modified. Avoid using any function call inside the assert method.You need to be sure that whatever code you add inside an Assert should not change the output if it is removed. This is when you implement Debug. Assert in your program.To implement it, you can use a temporary variable −int ... Read More

439 Views
A resizable implementation of the List interface is called ArrayList. It is a non-generic type of collection in C# that dynamically resizes.Let us see how to initialize ArrayList in C# −ArrayList arr= new ArrayList();Add an element like the below-given code snippet −ArrayList arr1 = new ArrayList(); arr1.Add(120); arr1.Add(160);Let us see the complete example to implement ArrayList in C# −ExampleLive Demousing System; using System.Collections; public class MyClass { public static void Main() { ArrayList arr1 = new ArrayList(); arr1.Add(120); arr1.Add(160); ArrayList arr2 = new ArrayList(); ... Read More

292 Views
The following is a simple “Hello World” program in C# programming −ExampleLive Demousing System; namespace MyHelloWorldApplication { class MyDemoClass { static void Main(string[] args) { // display text Console.WriteLine("Hello World"); // display another text Console.WriteLine("Welcome!"); Console.ReadKey(); } } }OutputHello World Welcome!Let us see now what all it includes −using System − the using keyword is used to include the System namespace in the program.namespace declaration − A namespace is a collection of classes. The ... Read More

138 Views
The array is a collection of variables of the same type. They are stored contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.SyntaxTo declare an array in C# −type[] arrayName;Here, type − is the datatype of the array in C#.arrayName − The name of the array[ ] − Specify the size of the array.ExampleLet us see an example to understand how to declare an array in C# −Live Demousing System; namespace MyApplication { class MyClass { static void Main(string[] args) { // ... Read More