To remove a character, use the remove() method and set the index from where you want to delete the character.Firstly, set the string.string str1 = "Amit"; Console.WriteLine("Original String: "+str1);To delete a character at position 4.StringBuilder strBuilder = new StringBuilder(str1); strBuilder.Remove(3, 1);You can try to run the following code to remove nth character from a string.Example Live Demousing System; using System.Text; public class Demo { public static void Main(string[] args) { string str1 = "Amit"; Console.WriteLine("Original String: "+str1); StringBuilder strBuilder = new StringBuilder(str1); strBuilder.Remove(3, 1); str1 ... Read More
Let’s say we want to count the number of words in the following string −str1 = "Hello World!";Now you need to loop though till string length and increment the variable count on finding “ “, , \t as shown below −if(str1[a]==' ' || str1[a]=='' || str1[a]=='\t') { count++; }You can try to run the following code to count words in a given string in C#.Example Live Demousing System; public class Demo { public static void Main() { string str1; int a, count; str1 = "Hello World!"; a = 0; count = 1; while (a
Packages in JavaPackages 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.A namespace is designed for providing a way to keep one set of names separate from another. The class names declared in one namespace does not conflict with the same class names declared in another.Define a Package as −package package_name;Restrict the access of classes (or class members) to the classes within the same package, but in C# with namespaces you cannot achieve this.Namespace in C#A namespace is designed for providing a way ... Read More
Public access specifier allows a class to expose its member variables and member functions to other functions and objects. Any public member can be accessed from outside the class.In the below example the variables length and width have been declared public. Now you can even access them outside the Main() method.The variables are accessed using the instance of the class.Rectangle r = new Rectangle(); r.length = 4.5; r.width = 3.5;Let us see the complete code.ExampleUsing System; namespace RectangleApplication { class Rectangle { // member variables public double length; public double ... Read More
IEnumerable and IEnumerator both are interfaces in C#.IEnumerable is an interface defining a single method GetEnumerator() that returns an IEnumerator interface.This works for readonly access to a collection that implements that IEnumerable can be used with a foreach statement.IEnumerator has two methods MoveNext and Reset. It also has a property called Current.The following shows the implementation of IEnumerable and IEnumerator.Exampleclass Demo : IEnumerable, IEnumerator { // IEnumerable method GetEnumerator() IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); } public object Current { get { throw new NotImplementedException(); } } // ... Read More
Static ConstructorA static constructor is a constructor declared using static modifier. It is the first block of code executed in a class. With that, a static constructor executes only once in the life cycle of class.Instance ConstructorInstance constructor initializes instance data. Instance constructor is called when an object of class is created.The following example shows the difference between static and instance constructor in C#.Example Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Difference { class Demo { static int val1; int val2; static Demo() { ... Read More
Delegates in C#A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime.To declare a delegate.delegate Delegation has run-time flexibility i.e. you can easily change it at runtime. The instance you create in Delegation is of a known class.Inheritance in C#Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and speeds up implementation time.When creating a class, instead of writing completely new data members and ... Read More
For super keyword in Java, we have the base keyword in C#.Super keyword in Java refers immediate parent class instance. It is used to differentiate the members of superclass from the members of subclass, if they have same names. It is used to invoke the superclass constructor from subclass.C# base keyword is used to access the constructors and methods of base class. Use it within instance method, constructor, etc.Let us see an example of C# base.Example Live Demousing System; public class Animal { public string repColor = "brown"; } public class Reptile: Animal { string repColor = "green"; ... Read More
Internal variable is set using the internal access specifier.internal double length; internal double width;Any member with internal access specifier can be accessed from any class or method defined within the application in which the member is defined.Example Live Demousing System; namespace RectangleApplication { class Rectangle { //member variables internal double length; internal double width; double GetArea() { return length * width; } public void Display() { Console.WriteLine("Length: {0}", length); Console.WriteLine("Width: ... Read More
The IsReadOnly property of Hashtable class is used to get a value indicating whether the Hashtable is read-only.Example Live Demousing System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { Hashtable ht = new Hashtable(); ht.Add("One", "Amit"); ht.Add("Two", "Aman"); ht.Add("Three", "Raman"); Console.WriteLine("IsReadOnly = " + ht.IsReadOnly); Console.ReadKey(); } } }OutputIsReadOnly = FalseAbove we have set a Hashtable with three elements.ht.Add("One", "Amit"); ht.Add("Two", "Aman"); ht.Add("Three", "Raman");After that, we have checked using the IsReadOnly property.Console.WriteLine("IsReadOnly = " + ht.IsReadOnly);
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP