Found 27759 Articles for Server Side Programming

What is the IsReadOnly property of BitArray class in C#?

George John
Updated on 23-Jun-2020 09:57:43

50 Views

The BitArray class is used when you need to store the bits but do not know the number of bits in advance.Using the IsReadOnly class, you can get a value indicating whether the BitArray is read-only or not. ReadOnly will not allow you to add new elements to the BitArray.The following is our example stating how to use the IsReadOnly property of BitArray class in C#.Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          BitArray ba1 = new BitArray(5);          BitArray ba2 ... Read More

C# program to accept two integers and return the remainder

karthikeya Boyini
Updated on 23-Jun-2020 09:58:59

508 Views

Firstly, set the two numbers.int one = 250; int two = 200;Now pass those numbers to the following function.public int RemainderFunc(int val1, int val2) {    if (val2 == 0)    throw new Exception("Second number cannot be zero! Cannot divide by zero!");    if (val1 < val2)    throw new Exception("Number cannot be less than the divisor!");    else    return (val1 % val2); }Above we have checked for two conditions i.e.If the second number is zero, an exception occurs.If the first number is less than the second number, an exception occurs.To return remainder of two numbers, the following is ... Read More

What is the Item property of ArrayList class in C#?

Ankith Reddy
Updated on 23-Jun-2020 09:59:28

79 Views

Use the Item property of ArrayList class to get or set the element at the specified index in the ArrayList.The Item property is an indexer so you can use it without adding the property name.In the below example, we have used it like the following statement −Console.WriteLine("Element {0} is \"{1}\"", 2, arrList[1]);Let us see the complete example tolearn how to work with Item property.Example Live Demousing System; using System.Collections; class Demo {    public static void Main() {       ArrayList arrList = new ArrayList();       arrList.Add(45);       arrList.Add(78);       arrList.Add(88);       ... Read More

C# program to remove n-th character from a string

Samual Sam
Updated on 23-Jun-2020 09:43:17

571 Views

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

Covariance and Contravariance in C#

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

178 Views

To deal with classes effectively, use the concept of covariance and contra variance. Let us consider the following as our class. One is a base class for class Two, whereas Two is a base class for Three. class One { } class Two: One { } class Three : Two { } A base class can hold a derived class, but the opposite is not possible. With Covariance, you can pass a derived type where a base type is expected. Co-variance can be used on array, interface, delegates, etc in C#. Contra variance is for parameters. ... Read More

C# program to replace n-th character from a given index in a string

Arjun Thakur
Updated on 23-Jun-2020 09:43:40

897 Views

Firstly, set a string.string str1 = "Port"; Console.WriteLine("Original String: "+str1);Now convert the string into character array.char[] ch = str1.ToCharArray();Set the character you want to replace with the index of the location. To set a character at position 3rd.ch[2] = 'F';To remove nth character from a string, try the following C# code. Here, we are replacing the first character.Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(string[] args) {       string str1 = "Port";       Console.WriteLine("Original String: "+str1);       char[] ch = str1.ToCharArray();       ch[0] = 'F';   ... Read More

Cohesion in C#

Samual Sam
Updated on 30-Jul-2019 22:30:23

1K+ Views

Cohesion in C# shows the relationship within modules. It shows the functional strength of the modules. The greater the cohesion, the better will be the program design. It is the dependency between the modules internal elements like methods and internal modules. High cohesion will allow you to reuse classes and method. An example of High cohesion can be seen in System.Math class i.e.it has Mathematical constants and static methods − Math.Abs Math.PI Math.Pow A class that does a lot of things at a time is hard to understand and maintain. This is what we call low cohesion and ... Read More

Decimal Functions in C#

Chandu yadav
Updated on 23-Jun-2020 09:44:15

179 Views

The following are some of the decimal functions in C#.Sr.No.Name & Description1Add (Decimal, Decimal)Adds two specified Decimal values.2Ceiling(Decimal)Returns the smallest integral value that is greater than or equal to the specified decimal number.3Compare (Decimal, Decimal)Compares two specified Decimal values.4CompareTo(Decimal)Compares this instance to a specified Decimal object and returns a comparison of their relative values.5CompareTo(Object)Compares this instance to a specified object and returns a comparison of their relative values.6Divide (Decimal, Decimal)Divides two specified Decimal values.7Equals(Decimal)Returns a value indicating whether this instance and a specified Decimal object represent the same value.Let us see an example of Decimal Ceiling() method in C# that returns the smallest integral value greater than or equal to ... Read More

Coupling in C#

George John
Updated on 14-Apr-2020 11:09:33

2K+ Views

Coupling shows the relationship between modules in C# or you can say the interdependence between modules.There are two types of coupling i.e tight and loose coupling.Loose CouplingLoose coupling is preferred since through it changing one class will not affect another class. It reduces dependencies on a class. That would mean you can easily reuse it.Writing loosely coupled code has the following advantages −One module won’t break other modulesEnhances testabilityCode is easier to maintainGets less affected by changes in other components.Tight CouplingIn Tight Coupling, the classes and objects are dependent on each other and therefore reduce re-usability of code.Read More

Database Operations in C#

Samual Sam
Updated on 30-Jul-2019 22:30:23

1K+ Views

The most common databases used in C# are Microsoft SQL Server and Oracle. The following is done to work with databases. Connect Set the Database Name, Optional Parameters and Credentials. The username and password is needed to set a connection to the database. The connection string would look somewhat like this. private static string _connectionString = "Data Source=.;Integrated Security=SSPI;Initial Catalog=test;Application Name=Demo;Connection Timeout2w00"; Above, the Application Name is Demo. Select Statement To fetch data from the database, the SELECT statement is used Insert The INSERT command is used to insert data in the database. Update The database ... Read More

Advertisements