Tutorialspoint

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

Ankith Reddy
Answered 4h 52m ago

Trim A 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 sparrow The following is an example − Example Live Demo using System; ... Read More

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

karthikeya Boyini
Answered 4h 55m ago

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. Variables Declaring a variable. int x; Let’s define and assign a value. x = ... Read More

TrimEnd() method in C#

George John
Answered 4h 55m ago

The TrimEnd() method removes all trailing occurrences of a set of characters specified in an array. For example, the following string has trailing 1s. String str ="234561111". We can easily remove the above trailing 1s from a string using the TrimEnd() method. Let us see an example to ... Read More

The Object Class in C#

Samual Sam
Answered 4h 59m ago

The Object class is the base class of all the classes in C#. It has the following methods on C#. Sr.No Method & Description 1 Equals(Object) Determines whether the specified object is equal to the current object. 2 Equals(Object, Object, Determines whether the specified ... Read More

Different ways for Integer to String Conversions in C#

Chandu yadav
Answered 5h 0m ago

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 ... Read More

How to generate the first 100 even Numbers using C#?

karthikeya Boyini
Answered 5h 5m ago

To generate first 100 even numbers, set a for loop from 1 to 100. for(val = 1; val <= 100; val++) {} Under the loop, set the condition for even numbers i.e. if the mod 2 of a number is 0, then it is an even number. ... Read More

Using the new keyword in C#

Maheshwari Thakur
Answered 5h 5m ago

Use the new keyword to create an instance of the array. The new operator is used to create an object or instantiate an object. Here in the example an object is created for the class using the new. The following is an example. Calculate c = new Calculate(); ... Read More

Typeof() vs GetType() in C#

Samual Sam
Answered 5h 9m ago

Typeof() The type takes the Type and returns the Type of the argument. For example: System.Byte for the following − typeof(byte) The following is an example − Example Live Demo using System; class Program { static void Main() { ... Read More

Remove Leading Zeros from a String in C#

Ankith Reddy
Answered 5h 9m ago

Let’s say the following is our string with leading zeros. String str ="000234"; Use the TrimStart() method and set the 0 to remove it. TrimStart(new Char[] { '0' } ) The following is the complete code to remove leading zeros. Example Live Demo using ... Read More

Random Numbers in C#

karthikeya Boyini
Answered 5h 14m ago

To generate random numbers in C#, use the Next(minValue, MaxValue) method. The parameters are used to set the minimum and maximum values. Next(100, 200); We have set the above method under Random() object. Random rd = new Random(); int rand_num = rd.Next(100, 200); The following is ... Read More

Implementing Stacks in C#

George John
Answered 5h 15m ago

Stack class is implemented in C# using Push and Pop operations. Stack is used in C# to represents last-in, first out collection of object. The following are the methods of Stack class − Sr.No. Method & Description 1 public virtual void Clear(); Removes all elements ... Read More

What is the difference between Write() and WriteLine() methods in C#?

Samual Sam
Answered 5h 18m ago

The difference between Write() and WriteLine() method is based on new line character. Write() method displays the output but do not provide a new line character. WriteLine() method displays the output and also provides a new line character it the end of the string, This would set a new line ... Read More

How to generate the first 100 Odd Numbers using C#?

Chandu yadav
Answered 5h 18m ago

To generate first 100 odd numbers, set a for loop from 1 to 100. for(val = 1; val <l= 100; val++) {} Under the loop, set the condition for odd numbers i.e. if the mod 2 of a number is not equal to 0, then it is an ... Read More

What is the System.Console class and its methods in C#?

karthikeya Boyini
Answered 5h 22m ago

The System.Console class in C# represents the standard input, output, and error streams for console applications. The following are some of the methods of the System.Console class − Refer: MSDN System Class methods Sr.No Method & Description 1 Beep() Plays the sound of a beep ... Read More

What is the difference between break and continue statements in C#?

George John
Answered 5h 22m ago

The break statement terminates the loop and transfers execution to the statement immediately following the loop. The continue statement causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. When the break statement is encountered inside a loop, the loop is immediately terminated and ... Read More

Advertisements
Loading...
Unanswered Questions View All