Chandu yadav has Published 1091 Articles

String format for Double in C#

Chandu yadav

Chandu yadav

Updated on 21-Jun-2020 16:35:00

2K+ Views

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 string −Exampleusing System; class Demo {    public static void Main(String[] args) {       Console.WriteLine("Three decimal ... Read More

Private Methods in C#

Chandu yadav

Chandu yadav

Updated on 21-Jun-2020 16:26:34

8K+ Views

Private Methods can only be used inside the class. To set private methods, use the private access specifier.Private access specifier allows a class to hide its member variables and member functions from other functions and objects. Only functions of the same class can access its private members. Even an instance ... Read More

Optional property in a C# class

Chandu yadav

Chandu yadav

Updated on 21-Jun-2020 16:11:09

5K+ Views

A property is optional if it is possible and valid for it to have null. A property whose CLR type cannot have null cannot be configured optional.An example optional attribute usage −Example[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] internal sealed class OptionalAttribute : Attribute { } public class Employee ... Read More

Print with your own font using C#

Chandu yadav

Chandu yadav

Updated on 21-Jun-2020 16:03:42

506 Views

To print your own font in C#, firstly construct −FontFamily objectFont ObjectThe FontFamily object sets the typeface like Arial, TimesNewRoman, etc, whereas the Font object sets the size and style of font.Let us create an Arial font style.FontFamily myFontFamily = new FontFamily("Arial"); Font myFont = new Font( myFontFamily, 20, FontStyle.Bold, ... Read More

Reverse a string in C#

Chandu yadav

Chandu yadav

Updated on 21-Jun-2020 15:54:35

584 Views

To reverse a string, use the Array. Reverse() method.We have set a method and passed the string value as “Henry” −public static string ReverseFunc(string str) {    char[] ch = str.ToCharArray();    Array.Reverse(ch);    return new string(ch); }In the above method, we have converted the string into character array −char[] ... Read More

Reverse words in a given String in C#

Chandu yadav

Chandu yadav

Updated on 21-Jun-2020 15:53:26

688 Views

Let’s say the following is the string −WelcomeAfter reversing the string, the words should be visible like −emocleWUse the reverse() method and try the following code to reverse words in a string −Exampleusing System; using System.Linq; class Demo {    static void Main() {       string ... Read More

What is the HashSet, C# Set collection in C#?

Chandu yadav

Chandu yadav

Updated on 21-Jun-2020 15:46:43

310 Views

HashSet in C# eliminates duplicate strings or elements in an array.In C#, it is an optimized set collection.Let us see an example to remove duplicate strings using C# HashSet −Exampleusing System; using System.Collections.Generic; using System.Linq; class Program {    static void Main() {       string[] arr1 = ... Read More

Generics vs non-generics in C#

Chandu yadav

Chandu yadav

Updated on 21-Jun-2020 15:28:39

6K+ Views

There are two types of collections in C#: non-generic collections and generic collections.Generics in C#Generic collections hold elements of same datatypes.For example −ListDictionaryHashsetDictionary − Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.Hashset − HashSet in C# eliminates duplicate strings or ... Read More

What is index-based I/O BitArray collection in C#?

Chandu yadav

Chandu yadav

Updated on 21-Jun-2020 15:21:05

188 Views

The BitArray class manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on (1) and false indicates the bit is off (0).The following are the method of the index-based BitArray collection −Sr.No.Method & Description1public BitArray And(BitArray value);Performs the bitwise AND ... Read More

Generics in C#

Chandu yadav

Chandu yadav

Updated on 21-Jun-2020 14:43:04

475 Views

Generics allow you to write a class or method that can work with any data type.Write the specifications for the class or the method, with substitute parameters for data types. When the compiler encounters a constructor for the class or a function call for the method, it generates code to ... Read More

Advertisements