Server Side Programming Articles - Page 2489 of 2646

Retrieve data value as a pointer in C#

Chandu yadav
Updated on 22-Jun-2020 07:50:46

916 Views

A pointer is a variable whose value is the address of another variable. Retrieve the data stored at the located referenced by the pointer variable, using the ToString() method.ExampleHere in an example −using System; namespace UnsafeCodeApplication {    class Program {       public static void Main() {          unsafe {             int var = 100;             int* p = &var;             Console.WriteLine("Data is: {0} " , var);             Console.WriteLine("Data is: {0} " , p->ToString());             Console.WriteLine("Address is: {0} " , (int)p);          }          Console.ReadKey();       }    } }OutputAbove will require you to set unsafe comman line option. After seeting it, the following output would be visible.Data is: 100 Data is: 100 Address is: 77678547

Abort in C#

Samual Sam
Updated on 22-Jun-2020 07:52:56

736 Views

The Abort() method is used for destroying threads.The runtime aborts the thread by throwing a ThreadAbortException. This exception cannot be caught, the control is sent to the finally block if any.Use the Abort() method on a thread −childThread.Abort();Example Live Demousing System; using System.Threading; namespace MultithreadingApplication {    class ThreadCreationProgram {       public static void CallToChildThread() {          try {             Console.WriteLine("Child thread starts");             // do some work, like counting to 10             for (int counter = 0; counter

Difference between TrimStart() and TrimEnd() in C#

Arjun Thakur
Updated on 22-Jun-2020 07:53:25

1K+ Views

TrimStart() method removes all leading occurrences of a set of characters, whereas TrimEnd()removes all trailing occurrences of a set of characters.TrimStart()The TrimStart() method removes all leading occurrences of a set of characters specified in an array.Let us see an example to remove all leading zeros −Example Live Demousing System; class Program {    static void Main() {       String str ="0009678".TrimStart(new Char[] { '0' } );       Console.WriteLine(str);    } }Output9678TrimEnd()The TrimEnd() method removes all trailing occurrences of a set of characters specified in an array.Let us see an example to remove all trailing 1s −Example Live ... Read More

What is the difference between pass by value and reference parameters in C#?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

996 Views

Reference Parameters A reference parameter is a reference to a memory location of a variable. The reference parameters represent the same memory location as the actual parameters that are supplied to the method. When you pass parameters by reference, unlike value parameters, a new storage location is not created for these parameters. Pass by Value This is the default mechanism for passing parameters to a method. In this mechanism, when a method is called, a new storage location is created for each value parameter. The values of the actual parameters are copied into them. Hence, the changes made to the ... Read More

What is the difference between overriding and hiding in C#?

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

2K+ Views

Method hiding is also called shadowing in C#. The method of the parent class is available to the child class without using the override keyword in shadowing. The child class has its own version of the same function. Define a behavior that is specific to the subclass type in overriding, you, which means a subclass can implement a parent class method based on its requirement. Hiding redefines the complete method, whereas overriding redefines only the implementation of the method. In Overriding, you can access the base class using the child class’ object overridden method.. Shadowing has cannot access the ... Read More

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

George John
Updated on 22-Jun-2020 07:40:15

857 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 a = Console.Read() Console.WriteLine(a);ReadLine()It 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...

What is the difference between initialization and assignment of values in C#?

Chandu yadav
Updated on 30-Jul-2019 22:30:23

1K+ Views

Let us understand the difference between initialization and assignment of values. Declaring an array. int [] n // declaring Initialization Declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array. Array is a reference type, so you need to use the new keyword to create an instance of the array. int n= new int[10]; // initialization Let’s assign value. You can assign values to individual array elements, by using the index number − n[0] = 100; n[1] = 200 ... Read More

What is the difference between keywords const and readonly in C#?

karthikeya Boyini
Updated on 22-Jun-2020 07:41:19

423 Views

ConstConstant fields are the fields that cannot be modified. At the time of declaration, you need to assign a value to it.const int a = 5;ReadonlyA Read-only field is initialized at the time of declaration or you can also set it within the constructor.Let us see an example in which the read-only field is initialized inside the constructor −Exampleclass Calculate {    readonly int z;    public Demo( ) {       z = 20;    } }

What is the difference between objects and classes in C#?

Samual Sam
Updated on 22-Jun-2020 07:42:42

342 Views

C# has object and classes like Java. Objects are real-world entities and instance of a class. Access the members of the class using an object.To access the class members, you need to use the dot (.) operator after the object name. The dot operator links the name of an object with the name of a member, for example, Box Box1 = new Box();Above you can see Box1 is our object. We will use it to access the members.Box1.height = 3.0;You can also use it to call member functions.Box1.getVolume();The following is an example showing how objects and class work in C#.Example Live ... Read More

Infinity or Exception in C# when divide by 0?

Arjun Thakur
Updated on 22-Jun-2020 07:43:38

2K+ Views

Divide by zero is the System.DivideByZeroException, which is a class that handles errors generated from dividing a dividend with zero.Let us see an example.Example Live Demousing System; namespace ErrorHandlingApplication {    class DivNumbers {       int result;       DivNumbers() {          result = 0;       }       public void division(int num1, int num2) {          try {             result = num1 / num2;          } catch (DivideByZeroException e) {             Console.WriteLine("Exception caught: ... Read More

Advertisements