- 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
205 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
195 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
4K+ 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
250 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);
5K+ 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
157 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
577 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); } }
520 Views
OverridingUnder overriding, you can define a behavior that's specific to the subclass type, which means a subclass can implement a parent class method based on its requirement.Let us see an example of abstract classes that implements Overriding −Exampleusing System; namespace PolymorphismApplication { 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; ... Read More
207 Views
The Array.Copy() method in C# is used to copy section of one array to another array.The following is the syntax −Array.Copy(src, dest, length);Here,src = array to be copieddest = destination arraylength = how many elements to copyThe following is an example showing the usage of Copy(,,) method of array class in C# −Exampleusing System; class Program { static void Main() { int[] arrSource = new int[4]; arrSource[0] = 24; arrSource[1] = 33; arrSource[2] = 9; arrSource[3] = 45; int[] arrTarget = new int[3]; Array.Copy(arrSource, arrTarget, 3); Console.WriteLine("Destination Array ..."); foreach (int value in arrTarget) { Console.WriteLine(value); } } }
2K+ Views
Set a two-dimensional array and a one-dimensional array −int[, ] a = new int[2, 2] {{1, 2}, {3, 4} }; int[] b = new int[4];To convert 2D to 1D array, set the two dimensional into one-dimensional we declared before −for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { b[k++] = a[i, j]; } }The following is the complete code to convert a two-dimensional array to one-dimensional array in C# −Exampleusing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program { class twodmatrix { ... Read More