Server Side Programming Articles - Page 2493 of 2650

What is the difference between Read(), ReadKey() and ReadLine() methods in C#?

George John
Updated on 22-Jun-2020 07:44:43

2K+ Views

Read()The Read() reads the next characters from the standard input stream. If a key is pressed on the console, then it would close.int az = Console.Read() Console.WriteLine(z);ReadKey()It reads only a single charactare from the standard input stream.ReadLine()Reads the next line of characters from the standard input stream.Example Live Demousing System; class Program {    static void Main() {       int x = 10;       Console.WriteLine(x);       Console.Write("Press any key to continue... ");       Console.ReadLine();    } }Output10 Press any key to continue...

Increment and Decrement Operators in C#

Samual Sam
Updated on 22-Jun-2020 07:34:05

7K+ Views

Increment operator increases integer value by one i.e.int a = 10; a++; ++a;Decrement operator decreases integer value by one i.e.int a = 20; a--; --a;The following is an example demonstrating increment operator −Example Live Demousing System; class Program {    static void Main() {       int a, b;       a = 10;       Console.WriteLine(++a);       Console.WriteLine(a++);       b = a;       Console.WriteLine(a);       Console.WriteLine(b);    } }Output11 11 12 12The following is an example demonstrating decrement operator −int a, b; a = 10; // displaying decrement operator result Console.WriteLine(--a); Console.WriteLine(a--); b = a; Console.WriteLine(a); Console.WriteLine(b);

Inbuilt Data Structures in C#

Chandu yadav
Updated on 22-Jun-2020 07:34:37

538 Views

C# has a lot of inbuilt Data Structures. Here are two of them −ListGeneric List is a generic collection and the ArrayList is a non-generic collection. The size can be dynamicallyincreased using List, unlike Arrays.Let us see an example.We have set the List first −List myList = new List()ArrayListIt represents ordered collection of an object that can be indexed individually.Set an ArrayList as −ArrayList arr = new ArrayList(); arr.Add(67); arr.Add(34); arr.Add(99); arr.Add(45);

Important Keywords in C#

karthikeya Boyini
Updated on 22-Jun-2020 07:34:54

375 Views

Some of the key keywords in C#, include.SealedParamsInternalthisabstractSealedWhen you use sealed modifiers in C# on a method, then the method loses its capabilities of overriding. The sealed method should be part of a derived class and the method must be an overridden method.ParamsWhile declaring a method, you are not sure of the number of arguments passed as a parameter, then use params. C# param arrays can let you know about this.InternalInternal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly. Any member with internal access specifier can ... Read More

Difference between prefix and postfix operators in C#?

Arjun Thakur
Updated on 22-Jun-2020 07:35:26

7K+ Views

Prefix OperatorThe increment operator ++ if used as prefix on a variable, the value of variable gets incremented by 1. After that the value is returned unlike Postfix operator. It is called Prefix increment operator. In the same way the prefix decrement operator works but it decrements by 1.For example, an example of prefix operator −++a;The following is an example demonstrating Prefix increment operator −Example Live Demousing System; class Program {    static void Main() {       int a, b;       a = 50;       Console.WriteLine(++a);       b = a;     ... Read More

What is the difference between dynamic type variables and object type variables?

Samual Sam
Updated on 22-Jun-2020 07:36:03

2K+ Views

You can store any type of value in the dynamic data type variable. Type checking for these types of variables takes place at run-time.The Object Type is the ultimate base class for all data types in C# Common Type System (CTS). The object is an alias for System. Object class. The object types can be assigned values of any other types, value types, reference types, predefined or user-defined types.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 runtime.Example of ... Read More

What is the difference between Trim() and TrimStart() methods in C#?

Ankith Reddy
Updated on 22-Jun-2020 07:36:46

1K+ Views

TrimA string method that removes all the leading and trailing whitespaces in a string.For example, the string “jack sparrow“ would be returned as the following without leading and whitespaces using trim().jack sparrowThe following is an example −Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {          string str = " Amit ";          Console.WriteLine(str);          // trim          Console.WriteLine("After removing leading and trailing whitespace...");          string res = str.Trim();          Console.WriteLine(res); ... Read More

What is the difference between declaration and definition in C#?

karthikeya Boyini
Updated on 22-Jun-2020 07:37:03

12K+ Views

Declaration means that variable is only declared and memory is allocated, but no value is set.However, definition means the variables has been initialized.The same works for variables, arrays, collections, etc.VariablesDeclaring a variable.int x;Let’s define and assign a value.x = 10; ArraysDeclaring an array.int [] n // declaring int n= new int[10]; // initializingLet’s assign a value.n[0] = 100; n[1] = 200

The Object Class in C#

Samual Sam
Updated on 22-Jun-2020 07:38:24

2K+ Views

The Object class is the base class of all the classes in C#. It has the following methods on C#.Sr.NoMethod & Description1Equals(Object)Determines whether the specified object is equal to the current object.2Equals(Object, Object, Determines whether the specified object instances are considered equal.3Finalize()Allows an object to try to free resources4GetHashCode()default hash function.5GetType()Type of the current instance.6MemberwiseClone()shallow copy of the current Object.7ReferenceEquals(Object, Object)Determines whether the specified Object instances are the same instance.8ToString()Returns a string that represents the current object.Let us see an example how to create an object of a class in C#.Example Live Demousing System; namespace MyApplication {    class Demo { ... Read More

Different ways for Integer to String Conversions in C#

Chandu yadav
Updated on 22-Jun-2020 07:39:03

16K+ Views

The easiest way to convert an integer to a string in C# is using the ToString() method.Let us see an example −int a = 100; string str = a.ToString();Another way is to use Convert.ToString();b = 50; string str2 = Convert.ToString(b); Console.WriteLine(str2);The following is the example showing the different ways to convert integer to string.Example Live Demousing System; class Program {    static void Main() {       int a, b, c;       a = 10;       string str = a.ToString();       Console.WriteLine(str);       b = 50;       string str2 = Convert.ToString(b);       Console.WriteLine(str2);       c = 100;       string str3 = string.Format("{0}", c);       Console.WriteLine(str3);    } }Output10 50 100

Advertisements