
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

417 Views
Precision states the difference between float and double data type. Float is a single precision (32 bit) floating point data type. Double is a double precision (64 bit) floating point data type. Range of a float type − -3.4 x 1038 to + 3.4 x 1038 Range of a double type is − (+/-)5.0 x 10-324 to (+/-)1.7 x 10308 Default value of a float type − 0.0F Default value of a double type − 0.0D

5K+ Views
Initialization When you assign a value to a variable when it is declared, it is called Initialization. Here is an example − int val = 50; For array initialization, you may need a new keyword, whereas to initialize a variable, you do not need it. Instantiation When you create a new object in C# for a class using the new keyword, then it is called instantiation. Use the new operator to instantiate a class in C#. Here is an example showing two objects of Student class created using new keyword − Student s1 = new Student(); Student s2 = new Student();

1K+ Views
To truncate a file in C#, use the FileStream.SetLength method.Here is the syntax −public override void SetLength (long value);Here, int64 = Length of the streamValue < current LengthIf the value is less than the current length of the stream: The stream is truncated. If the current position is greater than the new length, the current position is moved to the last byte of the stream.Value > current LengthThe stream is expanded, and the current position remains the same. If the stream is expanded, the contents of the stream between the old and the new length are undefined.The following is an ... Read More

1K+ Views
To create a new file in C#, use the FileStream object.The following is the syntax −FileStream = new FileStream( , , , );Let us see an example for a file “test.dat”, which is created/ opened using File object −FileStream F = new FileStream("test.dat", FileMode.OpenOrCreate,FileAccess.ReadWrite);The following is an example −Exampleusing System; using System.IO; namespace FileIOApplication { class Program { static void Main(string[] args) { FileStream F = new FileStream("test.dat", FileMode.OpenOrCreate, FileAccess.ReadWrite); for (int i = 1; i

132 Views
Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application.When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class. 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.Let us see an ... Read More

8K+ Views
Static variables are used for defining constants because their values can be retrieved by invoking the class without creating an instance of it. Static variables can be initialized outside the member function or class definition. You can also initialize static variables inside the class definition.Example Live Demousing System; namespace StaticVarApplication { class StaticVar { public static int num; public void count() { num++; } public int getNum() { return num; } } class ... Read More

1K+ Views
To convert an ArrayList to Array, use the ToArray() method in C#.Firstly, set an ArrayList −ArrayList arrList = new ArrayList(); arrList.Add("one"); arrList.Add("two"); arrList.Add("three");Now, to convert, use the ToArray() method −arrList.ToArray(typeof(string)) as string[];Let us see the complete code −Example Live Demousing System; using System.Collections; public class Program { public static void Main() { ArrayList arrList = new ArrayList(); arrList.Add("one"); arrList.Add("two"); arrList.Add("three"); string[] arr = arrList.ToArray(typeof(string)) as string[]; foreach (string res in arr) { Console.WriteLine(res); } } }Outputone two three

565 Views
Set a linkelist collection −var list = new LinkedList();Now, add elements −list.AddLast("One"); list.AddLast("Two"); list.AddLast("Four");Now, let us add new elements in the already created LinkedList −LinkedListNode node = list.Find("Four"); list.AddBefore(node, "Three"); list.AddAfter(node, "Five");Let us now see how to traverse through the nodes in a Singly Linked List −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main(string[] args) { var list = new LinkedList < string > (); list.AddLast("One"); list.AddLast("Two"); list.AddLast("Four"); Console.WriteLine("Travering..."); foreach(var res in list) { ... Read More

278 Views
Firstly, set an array and initialize it −int[] arr = new int[] {34, 56, 12};To loop through all the elements of an array −for (int i = 0; i < arr.Length; i++) { Console.WriteLine(arr[i]); }Let us see the complete code −Exampleusing System; public class Program { public static void Main() { int[] arr = new int[] {34, 56, 12}; // Length Console.WriteLine("Length:" + arr.Length); for (int i = 0; i< arr.Length; i++) { Console.WriteLine(arr[i]); } } }

677 Views
To list all the substrings, use the Substring method and loop through the length of the string.Let’s say our string is −string myStr = "pqrz";Use nested loop and get the substring in a new string −for (int i = 1; i < myStr.Length; i++) { for (int start = 0; start