Found 2628 Articles for Csharp

How to reverse a String using C#?

Samual Sam
Updated on 21-Jun-2020 16:05:29

448 Views

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);Exampleusing System; namespace Demo {    class Program {       static void Main(string[] args) {          string str = "Amit";          char[] ch = str.ToCharArray();          Array.Reverse(ch);          foreach(var items in ch) {             Console.WriteLine(items);          }          Console.ReadLine();       }    } }

Private Methods in C#

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

6K+ 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 of a class cannot access its private members.The following is an example −Exampleusing System; class Demo {    private int displayOne() {       return 10;    }    public int displayTwo() {       return 10;    } } class Program {    static ... Read More

Overriding in C#

karthikeya Boyini
Updated on 21-Jun-2020 16:07:05

411 Views

Runtime polymorphism has method overriding that is also known as dynamic binding or late binding. It is implemented by abstract classes and virtual functions. Abstract classes contain abstract methods, which are implemented by the derived class.Let us see an example of abstract classes that implement runtime polymorphism and works with Overriding −Exampleusing System; namespace PolymorphismApplication {    abstract class Shape {       public abstract int area();    }    class Rectangle: Shape {       private int length;       private int width;       public Rectangle( int a = 0, int ... Read More

Numbers in C#

Arjun Thakur
Updated on 21-Jun-2020 16:08:01

129 Views

For numbers in C#, use the int type. It represents an integer, which is positive or negative whole number.Let us see how to add two integers in C# using mathematical operator + −using System; using System.Linq; class Program {    static void Main() {       int x = 20;       int y = 30;       int sum = 0;       sum = x + y;       Console.WriteLine(sum);    } }Now let us learn about the order in which these mathematical operators i.e. operator precedence.Operator precedence determines the grouping ... Read More

Null Pointer Exception in C#

Samual Sam
Updated on 21-Jun-2020 16:08:32

3K+ Views

NullReferenceException is a C# version of NullPointerException. To handle and catch it in C#, use try-catch.The below example shows that a variable is set to null and when we try to print it, it throws an exception that gets caught in the catch −Try {    a = null;    Console.WriteLine(a); }catch (NullPointerException ex) {    Console.WriteLine("Variable is Null!"); }The above will allow the exception to be caught and use catch for it.

Naming Conventions in C#

Ankith Reddy
Updated on 21-Jun-2020 16:08:58

2K+ Views

Naming convetion for classesA class definition starts with the keyword class followed by the class name; and the class body enclosed by a pair of curly braces. The following are the conventions for class names.Pascal CasingThe coding conventions for a class name is the the name of the class names, for example, it should being PascalCasing.public class EmployeeDetails {}Above, the class name EmployeeDetails is in PascalCasing.Noun or Noun PhrasesPrefer adding class names as noun or noun phrases −public class Employee {} Identifier is a name used to identify a class, variable, function, or any other user-defined item.The following are the ... Read More

Mutation Test tools in C#

karthikeya Boyini
Updated on 21-Jun-2020 16:10:08

250 Views

One of the best tools for mutation testing in C# is “VisualMutator” It is integrated with the .NET programming environment.The following are the features of VisualMutant, which is a mutation test tool −Measure the quality of the test suite.To create first-order mutants using built-in and custom mutation operators.View modified code fragments in C#.Run NUnit and XUnit tests on generated mutants.Provides information about passed and failed testsYou can also write the results to XML.View details about any mutant right after the start of the mutation testing processIt gives results as mutation score

Nested Classes in C#

George John
Updated on 21-Jun-2020 16:09:53

448 Views

Nested class is a class declared in another enclosing class. It is a member of its enclosing class and the members of an enclosing class have no access to members of a nested class.Let us see an example code snippet of nested classes in C# −Exampleclass One {    public int val1;    public class Two {       public int val1;    } } class Demo {    static void Main() {       One a = new One();       a.val1++;       One.Two ab = new One.Two();       ... Read More

Overloading in C#

Samual Sam
Updated on 21-Jun-2020 16:10:33

213 Views

Overloading is of two types in C#.Function OverloadingYou 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 −public static int mulDisplay(int one, int two) { } public static int mulDisplay(int one, int two, int three) { } public static int mulDisplay(int one, int two, int three, int four) { }Operator OverloadingOverloaded operators are functions with special names. The keyword operator is followed by the symbol for the operator being defined.public ... Read More

Optional property in a C# class

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

4K+ 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 {    public string EmpName { get; set; }    [Optional]    public string AlternativeName { get; set; } }

Advertisements