Found 34494 Articles for Programming

Mutation Testing in C#

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

184 Views

Mutational testing in C# includes verifying the quality of a test suite in the active solution. For this, use a tool called “VisualMutant”. It sets as an extension to the Visual Studio IDE. The following are the capabilities of a testing tool. The following are the features of VisualMutant, which is a mutation test tool − View modified code fragments in C#. Run NUnit and XUnit tests on generated mutants View details about any mutant right after the start of the mutation testing process It gives results as mutation score. Measure the quality of the test suite. To create ... Read More

Overloaded method and ambiguity in C#

George John
Updated on 21-Jun-2020 16:04:20

693 Views

With method overloading, you can have multiple definitions for the same function name in the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list.Let us see an example. In this the call would go to the method with a single parameter −Exampleusing System; class Student {    static void DisplayMarks(int marks1 = 90) {       Console.WriteLine("Method with one parameter!");    }    static void DisplayMarks(int marks1, int marks2 = 95) {       Console.WriteLine("Method with two parameters!");    } ... Read More

How to add an item to an ArrayList in C#?

Samual Sam
Updated on 21-Jun-2020 15:51:25

141 Views

ArrayList is a non-generic type of collection in C# that dynamically resizes.Let us see how to initialize ArrayList in C# −ArrayList arr= new ArrayList();Add an item to an Array List −ArrayList arr1 = new ArrayList(); arr1.Add(30); arr1.Add(70);Let us see the complete example to implement ArrayList in C#. Here we have two array lists. The 2nd array list is appended to the first list.Exampleusing System; using System.Collections; public class MyClass {    public static void Main() {       ArrayList arr1 = new ArrayList();       arr1.Add(30);       arr1.Add(70);       ArrayList arr2 = ... Read More

Initializing HashSet in C#

Ankith Reddy
Updated on 21-Jun-2020 15:50:18

610 Views

To initialize a HashSet.var h = new HashSet(arr1);Above, we have set an array in the HashSet. The following is the array −string[] arr1 = {    "electronics",    "accessories”,    "electronics", };The following is an example showing how to implement HashSet in C# −Exampleusing System; using System.Collections.Generic; using System.Linq; class Program {    static void Main() {       string[] arr1 = {          "electronics",          "accessories”,          "electronics",       };       Console.WriteLine(string.Join(",", arr1));       // HashSet       var h = new HashSet(arr1);       // eliminates duplicate words       string[] arr2 = h.ToArray();       Console.WriteLine(string.Join(",", arr2));    } }

c# Put spaces between words starting with capital letters

Arjun Thakur
Updated on 21-Jun-2020 15:52:44

3K+ Views

To place spaces in between words starting with capital letters, try the following example −Firstly, set the string.var str = "WelcomeToMyWebsite";As you can see above, our string isn’t having spaces before capital letter. To add it, use LINQ as we have done below −str = string.Concat(str.Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');The following is the complete code to place spaces between words beginning with capital letters −Exampleusing System; using System.Linq; class Demo {    static void Main() {       var str = "WelcomeToMyWebsite";       Console.WriteLine("Original String: "+str);     ... Read More

Reverse words in a given String in C#

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

513 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 str = "Welcome";       // reverse the string       string res = string.Join(" ", str.Split(' ').Select(s => new String(s.Reverse().ToArray())));       Console.WriteLine(res);    } }

String format for DateTime in C#

Samual Sam
Updated on 21-Jun-2020 15:54:17

336 Views

Format DateTime using String.Format method.Let us see an example −Exampleusing System; static class Demo {    static void Main() {       DateTime d = new DateTime(2018, 2, 8, 12, 7, 7, 123);       Console.WriteLine(String.Format("{0:y yy yyy yyyy}", d));       Console.WriteLine(String.Format("{0:M MM MMM MMMM}", d));       Console.WriteLine(String.Format("{0:d dd ddd dddd}", d));    } }Above we have first set the DateTime class object −DateTime d = new DateTime(2018, 2, 8, 12, 7, 7, 123);To format, we have used the String.Format() method and displayed date in different formats.String.Format("{0:y yy yyy yyyy}", d) String.Format("{0:M MM MMM MMMM}", d) String.Format("{0:d dd ddd dddd}", d

Serialization and Deserialization in C#

karthikeya Boyini
Updated on 21-Jun-2020 15:54:49

1K+ Views

Serialization converts objects into a byte stream and brings it to a form that it can be written on stream. This is done to save it to memory, file or database.Serialization can be performed as −Binary SerializationAll the members, even members that are read-only, are serializedXML SerializationIt serializes the public fields and properties of an object into XML stream conforming to a specific XML Schema definition language document.Let us see an example. Firstly set the stream −FileStream fstream = new FileStream("d:ew.txt", FileMode.OpenOrCreate); BinaryFormatter formatter=new BinaryFormatter();Now create an object of the class and call the constructor which has three parameters −Employee ... Read More

Reverse a string in C#

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

438 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[] ch = str.ToCharArray();Then the Reverse() method is used −Array.Reverse(ch);

Streams and Byte Streams in C#

Samual Sam
Updated on 21-Jun-2020 15:55:37

1K+ Views

A file is a collection of data stored in a disk with a specific name and a directory path. When a file is opened for reading or writing, it becomes a stream.The type of streams includes −Byte Streams − It includes Stream, FileStream, MemoryStream and BufferedStream.Character Streams − It includes Textreader-TextWriter, StreamReader, StraemWriter and other streams.Byte streams have classes that consider data in the stream as byte.Stream class is the base for other byte stream classes. The following are the properties −CanRead − Whether stream supports readingCanWrite − Whether stream supports writingLength − Length of the streamThe System.IO namespace has ... Read More

Advertisements