What are jagged arrays in C#?

karthikeya Boyini
Updated on 20-Jun-2020 17:27:26

142 Views

A Jagged array is an array of arrays in C#. You can declare and initialize it −int[][] rank = new int[1][]{new int[]{5,3,1}};The following is an example showing how to work with jagged arrays in C# −Exampleusing System; namespace Program {    class Demo {       static void Main(string[] args) {          int[][] rank = new int[][]{new int[]{1,2},new int[]{3,4}};          int i, j;          for (i = 0; i < 2; i++) {             for (j = 0; j < 2; j++) {                Console.WriteLine("a[{0}][{1}] = {2}", i, j, rank[i][j]);             }          }          Console.ReadKey();       }    } }OutputAbove, we have a jagged array of 2 array of integers −int[][] rank = new int[][]{new int[]{1,2},new int[]{3,4}};

What is the base class for all exceptions in C#?

Arjun Thakur
Updated on 20-Jun-2020 17:26:45

1K+ Views

The System.SystemException class is the base class for all predefined system exception. Some of the exception classes derived from the System.Exception class are the System.ApplicationException and System.SystemException classes.The System.ApplicationException class supports exceptions generated by application programs. Hence the exceptions defined by the programmers should derive from this class.The following are the exceptions under the base class System.SystemException −Sr.No.Exception Class & Description1System.IO.IOExceptionHandles I/O errors.2System.IndexOutOfRangeExceptionHandles errors generated when a method refers to an array index out of range.3System.ArrayTypeMismatchExceptionHandles errors generated when type is mismatched with the array type.4System.NullReferenceExceptionHandles errors generated from referencing a null object.5System.DivideByZeroExceptionHandles errors generated from dividing a dividend with zero.6System.InvalidCastExceptionHandles errors ... Read More

Try-Catch-Finally in C#

Samual Sam
Updated on 20-Jun-2020 17:26:18

5K+ Views

C# exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero.C# exception handling is performed using the following keywords −try − A try block identifies a block of code for which particular exceptions is activated. It is followed by one or more catch blocks.catch − A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception.finally − The finally block is used to execute a given set ... Read More

Substring in C#

karthikeya Boyini
Updated on 20-Jun-2020 17:24:37

423 Views

Substring is used to get the sub-parts of a string in C#. We have the substring() method for this purpose. Use the substring() method in C# to check each and every substring for unique characters. Loop it until the length of the string.If anyone the substring matches another, then it would mean that the string does not have unique characters.You can try to run the following code to determine if a string has all unique characters. The example shows the usage of Substring() method −Exampleusing System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public class Demo { ... Read More

Streams In C#

Ankith Reddy
Updated on 20-Jun-2020 17:21:47

4K+ Views

The stream is basically the sequence of bytes passing through the communication path. There are two main streams: the input stream and the output stream. The input stream is used for reading data from file (read operation) and the output stream is used for writing into the file (write operation).The FileStream class in the System.IO namespace helps in reading from, writing to and closing files. This class derives from the abstract class Stream.Create a FileStream object to create a new file or open an existing file. The following is the syntax −FileStream = new FileStream( , , , );Here, ... Read More

volatile keyword in C#

Samual Sam
Updated on 20-Jun-2020 17:21:20

544 Views

To reduce concurrency issues in C#, use the volatile keyword. Let us seen an example.The following is how you use a volatile keyword for public variable −class Program {    public volatile int a;    public void Program(int _a) {       i = _i;    } }Let us see another example: We have two static variables. Set them in a new method −_out = "Welcome!"; _new = true;We declared them as static before using volatile −static string _out; static volatile bool new;Now you need to run the method on a thread −new Thread(new ThreadStart(volatileFunc)).Start();Read the value of the ... Read More

What is the best IDE for C# on MacOS?

George John
Updated on 20-Jun-2020 17:20:26

686 Views

On Windows, the best IDE to run C# programs is Visual Studio. On MacOS, the best IDE can be considered as Monodevelop.Monodevelop is an open source IDE that allows you to run C# on multiple platforms i.e. Windows, Linux and MacOS. Monodevelop is also known as Xamarin Studio.Monodevelop has a C# compiler to run C# programs. It can be used on Windows, macOS and Linux.For Mac, a special version of MonoDevelop was introduced and it was called Visual Studio for Mac. It has many of the features of what the same IDE provides for Windows like tool for and IntelliSense ... Read More

Try/catch/finally/throw keywords in C#

karthikeya Boyini
Updated on 20-Jun-2020 17:20:08

2K+ Views

Exception handling is based on the following keywords and its usage −try − A try block identifies a block of code for which particular exceptions is activated. It is followed by one or more catch blocks.catch − A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception.finally − The finally block is used to execute a given set of statements, whether an exception is thrown or not thrown. For example, if you open a file, it must be closed ... Read More

What is #define pre-processor directive in C#?

Samual Sam
Updated on 20-Jun-2020 17:19:12

272 Views

The #define pre-processor directive defines a sequence of characters, called symbol. It creates symbolic constants.#define lets you define a symbol such that, by using the symbol as the expression passed to the #if directive, the expression evaluates to true.Here is an example −Example#define ONE #undef TWO using System; namespace Demo {    class Program {       static void Main(string[] args) {          #if (ONE && TWO)          Console.WriteLine("Both are defined");          #elif (ONE && !TWO)          Console.WriteLine("ONE is defined and TWO is undefined");          #elif (!ONE && TWO)          Console.WriteLine("ONE is defined and TWO is undefined");          #else          Console.WriteLine("Both are undefined");          #endif       }    } }

What is the C# Equivalent of SQL Server DataTypes?

Chandu yadav
Updated on 20-Jun-2020 17:18:20

12K+ Views

The following table displays the C# equivalent of SQL Server datatypes −SQL Server data typeEquivalent C# data typevarbinaryByte[]binaryByte[]imageNonevarcharNonecharNonenvarcharString, Char[]ncharString, Char[]textNonentextNonerowversionByte[]bitBooleantinyintBytesmallintInt16intInt32bigintInt64smallmoneyDecimalmoneyDecimalnumericDecimaldecimalDecimalrealSinglefloatDoublesmalldatetimeDateTimedatetimeDateTimetableNonecursorNonetimestampNonexmlNone

Advertisements