How to compare two arrays in C#?

Samual Sam
Updated on 21-Jun-2020 13:26:44

882 Views

Firstly, set the two arrays to be compared −// two arrays int[] arr = new int[] { 99, 87, 56, 45}; int[] brr = new int[] { 99, 87, 56, 45 };Now, use SequenceEqual() to compare the two arrays −arr.SequenceEqual(brr);The following is the code to compare two arrays −Exampleusing System; using System.Linq; namespace Demo {    class Program {       static void Main(string[] args) {          // two arrays          int[] arr = new int[] { 99, 87, 56, 45};          int[] brr = new int[] { 99, 87, 56, 45 };          // compare          Console.WriteLine(arr.SequenceEqual(brr));       }    } }

How to compare two Dates in C#?

George John
Updated on 21-Jun-2020 13:25:22

815 Views

To compare dates in C#, you need to first set two dates to be compared using the DateTime object. We will use the DateTime class in C# −Date 1DateTime date1 = new DateTime(2018, 08, 05); Console.WriteLine("Date 1 : {0}", date1);Date 2DateTime date2 = new DateTime(2018, 08, 07); Console.WriteLine("Date 2 : {0}", date2);Now let us compare both the dates in C#. The following is an example to compare dates in C# −Exampleusing System; namespace Program {    class Demo {       static int Main() {          DateTime date1 = new DateTime(2018, 08, 05);       ... Read More

How to compare two dictionaries in C#?

karthikeya Boyini
Updated on 21-Jun-2020 13:18:26

3K+ Views

To compare two dictionaries, firstly set the two dictionaries −Dictionary OneIDictionary d = new Dictionary(); d.Add(1, 97); d.Add(2, 89); d.Add(3, 77); d.Add(4, 88); // Dictionary One elements Console.WriteLine("Dictionary One elements: "+d.Count);Dictionary OneIDictionary d2 = new Dictionary(); d2.Add(1, 97); d2.Add(2, 89); d2.Add(3, 77); d2.Add(4, 88); // Dictionary Two elements Console.WriteLine("Dictionary Two elements: "+d2.Count);Now let us compare them −bool equal = false; if (d.Count == d2.Count) { // Require equal count.    equal = true;    foreach (var pair in d) {       int value;       if (d2.TryGetValue(pair.Key, out value)) {          if ... Read More

Download webpage in Java

Vikyath Ram
Updated on 21-Jun-2020 13:16:19

2K+ Views

We can download a web page using its URL in Java. Following are the steps needed.Create URL object using url string.Download webpage in JavaCreate a BufferReader object using url.openStream() method.BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));Create a BufferWriter object to write to a file.BufferedWriter writer = new BufferedWriter(new FileWriter("page.html"));Read each line using BufferReader and write using BufferWriter.String line; while ((line = reader.readLine()) != null) { writer.write(line); }Following is the complete program to download a given URL page at current location.import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; public class Tester {    public static void main(String ... Read More

Value parameters vs Reference parameters vs Output Parameters in C#

Chandu yadav
Updated on 21-Jun-2020 13:15:38

2K+ Views

Value parametersThe value parameters copy the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument.This is the default mechanism for passing parameters to a method. In this mechanism, when a method is called, a new storage location is created for each value parameter.The values of the actual parameters are copied into them. Hence, the changes made to the parameter inside the method have no effect on the argument.Reference ParametersA reference parameter is a reference to a memory location of a ... Read More

How to add easing effect to your animation with jQuery?

Ricky Barnes
Updated on 21-Jun-2020 13:14:24

468 Views

To add easing effect to your animation, use the animation speed properly to form it a perfect animation for the web page. Do not speed up animation and you should know where to stop it while using animate().Here for our example, we have a button that takes you to a textarea to add an answer:    Add answer Now set the fade out property properly to set easing effect.Example Live Demo               $(document).ready(function(){          $('body').on('click', '#answer', function() {             var container = $('.new-answer');   ... Read More

How to convert Trigonometric Angles in Radians using C#?

Samual Sam
Updated on 21-Jun-2020 13:13:04

3K+ Views

To convert trigonometric angles in Radians, multiply by Math.PI/180. This will convert degrees to radians.The following is the code −Exampleusing System; class Program {    static void Main() {       Console.WriteLine(Math.Cos(45));       double res = Math.Cos(Math.PI * 45 / 180.0);       Console.WriteLine(res);    } }Above, we converted using the following formulae −Math.PI * angle / 180.0

Dynamic method dispatch or Runtime polymorphism in Java

Rishi Raj
Updated on 21-Jun-2020 13:12:05

9K+ Views

Runtime Polymorphism in Java is achieved by Method overriding in which a child class overrides a method in its parent. An overridden method is essentially hidden in the parent class, and is not invoked unless the child class uses the super keyword within the overriding method. This method call resolution happens at runtime and is termed as Dynamic method dispatch mechanism.ExampleLet us look at an example.class Animal {    public void move() {       System.out.println("Animals can move");    } } class Dog extends Animal {    public void move() {       System.out.println("Dogs can walk and ... Read More

How to access elements from a rectangular array in C#?

karthikeya Boyini
Updated on 21-Jun-2020 13:11:30

167 Views

To access elements from a rectangular array, you just need to set the index of which you want to get the element. Multi-dimensional arrays are also called rectangular array −a[0, 1]; // second elementThe following is an example showing how to work with a rectangular array in C# and access an element −Exampleusing System; namespace Demo {    class Program {       static void Main(string[] args) {          int[, ] a = new int[3, 3];          a[0, 0]= 10;          a[0, 1]= 20;       ... Read More

How to convert Upper case to Lower Case using C#?

George John
Updated on 21-Jun-2020 13:10:21

2K+ Views

To convert Upper case to Lower case, use the ToLower() method in C#.Let’s say your string is −str = "TIM";To convert the above uppercase string in lowercase, use the ToLower() method −Console.WriteLine("Converted to LowerCase : {0}", str.ToLower());The following is the code in C# to convert character case −Exampleusing System; using System.Collections.Generic; using System.Text; namespace Demo {    class MyApplication {       static void Main(string[] args) {          string str;          str = "TIM";          Console.WriteLine("UpperCase : {0}", str);          // convert to lowercase          Console.WriteLine("Converted to LowerCase : {0}", str.ToLower());          Console.ReadLine();       }    } }

Advertisements