Samual Sam has Published 2492 Articles

What are the main parts of a C# program?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 15:32:32

2K+ Views

The main parts of a C# program includes −Namespace declarationA classClass methodsClass attributesA Main methodStatements and ExpressionsCommentsThe following is an example showing how to create a C# program −Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {       ... Read More

How to use C# BinaryWriter class?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 15:29:26

106 Views

If you want to write binary information into the stream, then use the BinaryWriter class in C#. You can find it under the System.IO namespace.The following is the implementation of the BinaryWriter class −static void WriteMe() {    using (BinaryWriter w = new BinaryWriter(File.Open("C:\abc.txt", FileMode.Create))) {       w.Write(37.8); ... Read More

How to use C# FileStream class?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 15:27:34

199 Views

A stream for file operations such as read and write is provided by the FileStream class.Create an object like thisFileStream fstream = new FileStream("d:ew.txt", FileMode.OpenOrCreate);Above we have used FileMode.OpenOrCreate so that the file or opened or created if it does not already exist.The following is n example showing how to ... Read More

How to call custom methods in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 15:25:24

257 Views

To define a custom method in C#, use the following syntax − (Parameter List) {    Method Body }To call a custom method, try to run the following code. It has the checkPalindrome() method which is called to checker whether the binary representation is Palindrome or not −Example Live Demousing ... Read More

What does the interface IEnumerable do in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 15:22:15

11K+ Views

IEnumerable is an interface defining a single method GetEnumerator() that returns an IEnumerator interface. It is the base interface for all non-generic collections that can be enumerated.This works for read-only access to a collection that implements that IEnumerable can be used with a foreach statement.It has a single method −GetEnumerator() ... Read More

What does the interface IStructuralComparable do in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 15:21:07

135 Views

The IStructuralComparable interface supports the structural comparison of collection objects. This interface introduced in .NET 4.The following is the syntax −public interface IStructuralComparableIt has a single method −CompareTo(Object,  IComparer) − It determines whether the current collection object precedes, occurs in the same position as, or follows another object in the ... Read More

What are the different types of conditional statements supported by C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 15:18:33

2K+ Views

The conditional statement requires the programmer to specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to ... Read More

What does the keyword var do in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 15:13:58

307 Views

The "var" keyword initializes variables with var support. Just assign whatever value you want for the variable, integer, string, float, etc.Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {          var myInt = 5;       ... Read More

How to use #error and #warning directives in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 15:08:10

428 Views

#error directiveThe #error directive allows generating an error from a specific location in your code.Let us see an example −Example Live Demousing System; namespace Demo {    class Program {       public static void Main(string[] args) {          #if (!ONE)          #error ... Read More

Iterator Functions in C#

Samual Sam

Samual Sam

Updated on 20-Jun-2020 15:01:31

605 Views

An iterator method performs a custom iteration over a collection. It uses the yield return statement and returns each element one at a time. The iterator remembers the current location and in the next iteration the next element is returned.The following is an example −Example Live Demousing System; using System.Collections.Generic; using ... Read More

Advertisements