Tutorialspoint

Retrieving Elements from Collection in C#

karthikeya Boyini
Answered 2d 1h ago

Let us see an example of a list collection. We have set the elements − List<int> list = new List<int>(); list.Add(20); list.Add(40); list.Add(60); list.Add(80); Now let’s say we need to retrieve the first element from the list. For that, set the index like this − int a ... Read More

return keyword in C#

Maheshwari Thakur
Answered 2d 1h ago

The return statement is used to return value. When a program calls a function, the program control is transferred to the called function. The following is an example to learn about the usage of return statement in C#. Here, we are finding the average and returning the result using ... Read More

String Literal Vs String Object in C#

Samual Sam
Answered 2d 1h ago

String Literals String literals or constants are enclosed in double quotes "" or with @"". A string contains characters that are similar to character literals: plain characters, escape sequences, and universal characters. Here are some examples of String Literals − Hello, World" "Welcome, \ The following is an ... Read More

String format for Double in C#

Chandu yadav
Answered 2d 1h ago

Use the static method String.Format for form double string format in C#. For three decimal places − String.Format("{0:0.000}", 987.383); String.Format("{0:0.000}", 987.38); String.Format("{0:0.000}", 987.7899); For thousands separator − String.Format("{0:0, 0.0}", 54567.46); String.Format("{0:0, 0}", 54567.46); To format ... Read More

Static vs. Non-Static method in C#

karthikeya Boyini
Answered 2d 1h ago

Declare a member function as static. Such functions can access only static variables. The static functions exist even before the object is created. A static class cannot be instantiated and can only contain static members. Static methods is set using static keyword − public static int getNum() { ... Read More

Swap two variables in one line using C#

George John
Answered 2d 1h ago

To swap two variables in a single line using the Bitwise XOR Operator. val1 = val1 ^ val2 ^ (val2 = val1); Above, we have set the values − int val1 = 30; int val2 = 60; The following is the example to swap both the ... Read More

Swap two Strings without using temp variable in C#

Samual Sam
Answered 2d 1h ago

To swap two strings without using a temp variable, you can try the following code and logic. Append the second string with the first. str1 = str1 + str2; Set the str1 in str2. str2 = str1.Substring(0, str1.Length - str2.Length); Now, the final step is to ... Read More

Tasks in C#

Ankith Reddy
Answered 2d 1h ago

Task represents an asynchronous operation in C#. The following states how you can start a task in C#. Use a delegate to start a task. Task t = new Task(delegate { PrintMessage(); }); t.Start(); Use Task Factory to start a task. Task.Factory.StartNew(() => {Console.WriteLine("Welcome!"); }); You ... Read More

Timer in C#

karthikeya Boyini
Answered 2d 1h ago

The namespace used to set a timer is System. Timers. The Timer class generates an event after a set interval, with an option to generate recurring events. Firstly, create a timer object for 5 seconds interval − timer = new System.Timers.Timer(5000); Set elapsed event for the timer. This ... Read More

try keyword in C#

Maheshwari Thakur
Answered 2d 1h ago

A try block identifies a block of code for which particular exceptions is activated. It is followed by one or more catch blocks. try { } With that, you need to set catch statement as well to catch the exception − try { // ... Read More

Trim (Remove leading and trailing spaces) a string in C#

Samual Sam
Answered 2d 1h ago

To trim a string in C#, use regular expression. Firstly, set the pattern for regex − string pattern = "\\s+"; Let’s say the following is our string with leading and trailing spaces − string input = " Welcome ... Read More

Packages in C#

Ankith Reddy
Answered 2d 1h ago

As an alternative of Packages in Java, the C# language has namespace. Packages in Java Packages are used in Java in order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations easier, etc. Namespace in C# A namespace is designed for ... Read More

How to swap two numbers without using a temp variable in C#

karthikeya Boyini
Answered 2d 1h ago

To swap two numbers, use the third variable and perform arithmetical operator without using a temp variable. Set two variables for swapping − val1 = 5; val2 = 10; Now perform the following operation for swap − val1 = val1 + val2; val2 = val1 - val2; ... Read More

Networking in C#

George John
Answered 2d 1h ago

The .NET Framework has a layered, extensible, and managed implementation of networking services. You can easily integrate them into your applications. Use the System.Net; namespace. Let us see how to acess the Uri class:.In C#, it provides object representation of a uniform resource identifier (URI) − Uri uri = ... Read More

How to reverse a String using C#?

Samual Sam
Answered 2d 1h ago

To reverse a string, use the Array.Reverse() method. Set the string you want to reverse − string str = "Amit"; In the above method, we have converted the string into character array − char[] ch = str.ToCharArray(); Then the Reverse() method is used. Array.Reverse(ch); ... Read More

Previous 1 ... 3 4 5 6 7 8 9 ... 724 Next
Advertisements
Loading...
Unanswered Questions View All