
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

925 Views
Firstly, declare a list −var teams = new List();To add items to a C# list, use the Add() method −teams.Add("US"); teams.Add("Canada"); teams.Add("India"); teams.Add("Australia");You can try to run the following code to add items to a list in C# −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main(string[] args) { var teams = new List(); teams.Add("US"); teams.Add("Canada"); teams.Add("India"); teams.Add("Australia"); Console.WriteLine("Elements..."); foreach (var countries in teams) { Console.WriteLine(countries); } } }

808 Views
A file is a collection of data stored in a disk with a specific name and a directory path. When a file is opened for reading or writing, it becomes a stream.In C#, you need to create a FileStream object to create a new file or open an existing file. The syntax for creating a FileStream object is as follows −FileStream = new FileStream( , , , );Here, the file operations are also included as shown below −The FileMode enumerator defines various methods for opening files. The members of the FileMode enumerator are −Append − It opens an existing ... Read More

243 Views
The System.Reflection namespace contains classes that allow you to obtain information about the application and to dynamically add types, values, and objects to the application.It has a module constructor that initializes a new instance of the Module class. A module is a portable executable file that has one or more classes and interfaces.Let us see an example of System.Reflection in C# −Exampleusing System; using System.Reflection; [AttributeUsage(AttributeTargets.All)] public class HelpAttribute : System.Attribute { public readonly string Url; public string Topic // Topic is a named parameter { get { return ... Read More

265 Views
Character literals are enclosed in single quotes. For example, 'x' and can be stored in a simple variable of char type. A character literal can be a plain character (such as 'x'), an escape sequence (such as '\t'), or a universal character (such as '\u02C0').Let us see an example how to define a character constant in C# −using System; namespace Demo { class Program { static void Main(string[] args) { Console.WriteLine("Welcome!\t"); Console.WriteLine("This is it!"); Console.ReadLine(); } } }Above, we ... Read More

6K+ Views
Use the param keyword to get the variable arguments in C#.Let us see an example to multiply integers. We have used params keyword to accept any number of int values −static int Multiply(params int[] b)The above allows us to find multiplication of numbers with one as well as two int values. The fllowing calls the same function with multiple values −int mulVal1 = Multiply(5); int mulVal2 = Multiply(5, 10);Let us see the complete code to understand how variable arguments work in C# −Exampleusing System; class Program { static void Main() { int mulVal1 = Multiply(5); ... Read More

426 Views
To create, move and delete directories in C#, the System.IO.Directory class has methods.Firstly, import the System.IO namespace.Now, use the Director.CreateDirectory() method to create a directory in the specified path −string myDir = @"D:\NEW"; if (!Directory.Exists(myDir)) { Directory.CreateDirectory(myDir); }In the same way, you can create a sub-directory −string mysubdir = @"C:\NEW\my\"; Directory.CreateDirectory(mysubdir);

7K+ Views
Value Type and Reference, both are types in C# −Value TypeValue type variables can be assigned a value directly. They are derived from the class System.ValueType. The value types directly contain data. When you declare an int type, the system allocates memory to store the value.Value Type variables are stored in the stack.Examples are int, char, and float, which stores numbers, alphabets, and floating point numbers, respectively.Reference TypeIt refers to a memory location. Using multiple variables, the reference types can refer to a memory location. If the data in the memory location is changed by one of the variables, the ... Read More

228 Views
Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.To create a dictionary, you first need to set it and add the key and values. Here we have added 5 keys with values to a Dictionary. We have set its keys and value type as int.IDictionary d = new Dictionary(); d.Add(1, 44); d.Add(2, 34); d.Add(3, 66); d.Add(4, 47); d.Add(5, 76);The following is the complete code −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main() { IDictionary d = new Dictionary(); d.Add(1, 44); ... Read More

897 Views
Use the Array.Count property in C# to count the number of items in a list in C# −Set the listList myList = new List() { "electronics", "clothing", "appliances", "accessories" };Now count the number of items in a list in C# −myList.CountThe following is the complete code to count the number of items in a list −Exampleusing System; using System.Collections.Generic; class Program { static void Main() { List myList = new List() { "electronics", "clothing", "appliances", "accessories" }; Console.WriteLine(myList.Count); } }