Csharp Articles

Page 159 of 196

What are nested namespaces in C#?

Ankith Reddy
Ankith Reddy
Updated on 20-Jun-2020 2K+ Views

A namespace inside a namespace is called a nested namespace in C#. This is mainly done to properly structure your code.We have an outer namespace −namespace outer {}Within that, we have an inner namespace inside the outer namespace −namespace inner {    public class innerClass {       public void display() {          Console.WriteLine("Inner Namespace");       }    } }Now to call the method of inner namespace, set a class object of the inner class and call the method as shown in the below example −namespace outer {    class Program {   ...

Read More

What are generic delegates in C#?

George John
George John
Updated on 20-Jun-2020 1K+ Views

Using generic delegates, you do not need to define the delegate statement. They are defined in the System namespace.You can define a generic delegate with type parameters. For example −delegate T myDelegete(T n);ExampleThe following is an example showing how to create generic delegates in C# −using System; using System.Collections.Generic; delegate T myDelegete(T n); namespace GenericDelegateAppl {    class TestDelegate {       static int num = 5;       public static int AddNum(int p) {          num += p;          return num;       }       ...

Read More

What are identifiers in C#?

Arjun Thakur
Arjun Thakur
Updated on 20-Jun-2020 1K+ Views

An identifier is a name used to identify a class, variable, function, or any other user-defined item. The basic rules for naming classes in C# are as follows −A name must begin with a letter that could be followed by a sequence of letters, digits (0 - 9) or underscore. The first character in an identifier cannot be a digit.It must not contain any embedded space or symbol such as? - + ! @ # % ^ & * ( ) [ ] { } . ; : " ' / and \. However, an underscore ( _ ) can ...

Read More

What are dynamic data types in C#?

George John
George John
Updated on 20-Jun-2020 632 Views

Store any type of value in the dynamic data type variable. Type checking for these types of variables takes place at run-time.The following is the syntax for declaring a dynamic type −dynamic = value;The following is an example −dynamic val1 = 100; dynamic val2 = 5; dynamic val3 = 20;The dynamic types are similar to object types except that type checking for object type variables takes place at compile time, whereas that for the dynamic type variables takes place at run time.

Read More

What are circular references in C#?

Ankith Reddy
Ankith Reddy
Updated on 20-Jun-2020 4K+ Views

Circular reference occurs when two or more interdependent resources cause lock condition. This makes the resource unusable.To handle the problem of circular references in C#, you should use garbage collection. It detects and collects circular references. The garbage collector begins with local and static and it marks each object that can be reached through their children.Through this, you can handle the issues with circular references.Let’s say the following classes is in circular reference. Here both of them depends on each other −public class A {    B Two; } public class B {    A one; }To solve the ...

Read More

What are I/O classes in C#?

Chandu yadav
Chandu yadav
Updated on 20-Jun-2020 980 Views

The System.IO namespace has various classes useful for performing various operations with files, such as creating and deleting files, reading from or writing to a file, closing a file etc.The following are the I/O classes in C# −Sr.No.I/O Class & Description1BinaryReaderReads primitive data from a binary stream.2BinaryWriterWrites primitive data in binary format.3BufferedStreamA temporary storage for a stream of bytes.4DirectoryHelps in manipulating a directory structure.5DirectoryInfoUsed for performing operations on directories.6DriveInfoProvides information for the drives.7FileHelps in manipulating files.8FileInfoUsed for performing operations on files.9FileStreamUsed to read from and write to any location in a file.10MemoryStreamUsed for random access to streamed data stored in ...

Read More

How to determine if the string has all unique characters using C#?

Arjun Thakur
Arjun Thakur
Updated on 20-Jun-2020 457 Views

To determine if a string has unique characters or not, firstly check a word in the string with the next word −for (int j = i + 1; j < val.Length; j++) {    if (val[i] == val[j]) }If you find a match, that would mean the string do not have unique characters.If you are unable to find a match, then the string has all unique characters.In case of a match, return false i.e. unique characters not found −for (int j = i + 1; j < val.Length; j++) {    if (val[i] == val[j])    return false; }

Read More

What are the C++ features missing in C#?

Chandu yadav
Chandu yadav
Updated on 20-Jun-2020 278 Views

C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg.C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.The following are some of the features of C++ missing in C# −In C#, Multiple Inheritance is not possible, whereas C++ can easily implement Multiple Inheritance.In C++, you need to manage memory manually and must allocate and deallocate memory for your objects.C++ can create standalone applications, whereas C# ...

Read More

How to capture file not found exception in C#?

Arjun Thakur
Arjun Thakur
Updated on 20-Jun-2020 430 Views

The file not found exception is raised when you try to find a file that does not exist.Let’s say I have set a file in StreamReader, “new.txt” that does not exist. If you will try to access it using StreamReader(to read it), it will throw FileNotFoundException −using (StreamReader sReader = new StreamReader("new.txt")) { sReader.ReadToEnd(); }To handle it, you need to use try and catch −Try {    using (StreamReader sReader = new StreamReader("new.txt")) {       sReader.ReadToEnd();    }    }catch (FileNotFoundException e) {       Console.WriteLine("File Not Found!");       Console.WriteLine(e);    }

Read More

How to control for loop using break and continue statements in C#?

George John
George John
Updated on 20-Jun-2020 269 Views

Break statement terminates the loop. To use it in a for loop, you can get input from user everytime and display the output when user enters a negative number. The output gets displayed then and exited using the break statement −for(i=1; i

Read More
Showing 1581–1590 of 1,951 articles
« Prev 1 157 158 159 160 161 196 Next »
Advertisements