- 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
78 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
679 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
646 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
2K+ Views
Public Access SpecifierPublic access specifier allows a class to expose its member variables and member functions to other functions and objects. Any public member can be accessed from outside the class.Example Live Demousing System; namespace Demo { class Rectangle { public double length; public double width; public double GetArea() { return length * width; } public void Display() { Console.WriteLine("Length: {0}", length); Console.WriteLine("Width: {0}", width); Console.WriteLine("Area: {0}", GetArea()); ... Read More
646 Views
An implementation of the property accessors will not be provided by an abstract property declaration.Let us see how to learn how to work with abstract properties. Here we have an abstract class Shape with two derived classes: Square and Circle.Here, we have an abstract Area property.The following is the Circle class.Examplepublic class Circle : Shape { private int radius; public Circle(int radius, string id) : base(id) { this.radius = radius; } public override double Area { get { return radius * radius * System.Math.PI; ... Read More
553 Views
To define the scope and visibility of a class member, use an access specifier. C# supports the following access specifiers − Public Private Protected Internal Protected internal Let us learn about them one by one. Public Access Specifier It allows a class to expose its member variables and member functions to other functions and objects. Private Access Specifier Private access specifier allows a class to hide its member variables and member functions from other functions and objects. Only functions of the same class can access its private members. Protected Access Specifier Protected access specifier allows a child class ... Read More
260 Views
Abstract classes contain abstract methods, which are implemented by the derived class. The derived classes have more specialized functionality.The following is an example showing the usage of abstract classes in C#.Example Live Demousing System; namespace Demo { abstract class Shape { public abstract int area(); } class Rectangle: Shape { private int length; private int width; public Rectangle( int a = 0, int b = 0) { length = a; width = b; Console.WriteLine("Length ... Read More
157 Views
All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element. To initialize an array, first you need to declare it. int[] marks; Here, int is the datatype [] specifies the size of the array Marks is the name of the array Now let us initialize the array using the new keyword. int[] marks = new int[10]; Now let us assign elements to it. marks[0] = 96; marks[1] = 90 You can also assign elements like this − int [] marks = new int[10] { 78, 67, 88, 56, 90, 77, 76, 70, 60, 70};
235 Views
Like any other programming language, in C#, you can easily create user-defined exception. User-defined exception classes are derived from the Exception class.In the below example, the exception created is not a built-in exception.TempIsZeroExceptionYou can try to run the following code to learn how to create user defined exception in C#.Example Live Demousing System; namespace Demo { class TestTemperature { static void Main(string[] args) { Temperature temp = new Temperature(); try { temp.showTemp(); } catch(TempIsZeroException e) { ... Read More