Programming Articles - Page 2288 of 3366

C# Queue.TrimExcess() Method with Examples

AmitDiwan
Updated on 02-Dec-2019 12:28:15

314 Views

The Queue.TrimExcess() method in C# is used to set the capacity to the actual number of elements in the Queue, if that number is less than 90 percent of current capacity.Syntaxpublic void TrimExcess ();Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       Queue queue = new Queue();       queue.Enqueue(100);       queue.Enqueue(200);       queue.Enqueue(300);       queue.Enqueue(400);       queue.Enqueue(500);       queue.Enqueue(600);       queue.Enqueue(700);       queue.Enqueue(800);       queue.Enqueue(900);       queue.Enqueue(1000);       Console.WriteLine("Queue..."); ... Read More

C# Object.GetType() Method with Examples

AmitDiwan
Updated on 10-Jul-2020 05:04:20

3K+ Views

The Object.GetTypeCode() method in C# is used to get the Type of the current instance.SyntaxThe syntax is as follows −public Type GetType ();Example Live Demousing System; public class Demo {    public static void Main() {       Object ob = new Object();       String str = "Jim";       Type type1 = ob.GetType();       Type type2 = str.GetType();       Console.WriteLine("Type = "+type1);       Console.WriteLine("Type = "+type2);       Console.WriteLine("Hash Code = "+type1.GetHashCode());       Console.WriteLine("Hash Code = "+type2.GetHashCode());    } }OutputType = System.Object Type = System.String Hash Code = 30015890 Hash Code = 21083178Example Live Demousing System; ... Read More

C# BitConverter.ToString(Byte[]) Method

AmitDiwan
Updated on 02-Dec-2019 12:16:46

2K+ Views

The BitConverter.ToString() method in C# is used to convert the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation.Syntaxpublic static string ToString (byte[] val);Above, val is the byte array.Example Live Demousing System; public class Demo {    public static void Main() {       byte[] arr = {0, 10, 2, 5, 32, 45};       int count = arr.Length;       Console.Write("Byte Array... ");       for (int i = 0; i < count; i++) {          Console.Write(""+arr[i]);       }       Console.WriteLine("Byte ... Read More

Single.Equals() Method in C# with Examples

AmitDiwan
Updated on 02-Dec-2019 12:11:42

100 Views

The Single.Equals() method in C# is used to return a value indicating whether two instances of Single represent the same value.Syntaxpublic bool Equals (float ob); public override bool Equals (object ob);The parameter ob for the both the syntaxes is an object to compare with this instance.Example Live Demousing System; public class Demo {    public static void Main() {       float f1 = 15.9f;       float f2 = 40.2f;       Console.WriteLine("Value1 = "+f1);       Console.WriteLine("Value2 = "+f2);         Console.WriteLine("Are both the values equal? = "+f1.Equals(f2));    } }OutputValue1 = 15.9 Value2 = 40.2 Are both the values equal? = FalseExample Live ... Read More

C# BitConverter.ToChar() Method

AmitDiwan
Updated on 02-Dec-2019 12:07:51

200 Views

The BitConverter.ToChar() method in C# is used to returns a Unicode character converted from two bytes at a specified position in a byte array.Syntaxpublic static char ToChar (byte[] value, int begnIndex);Above, val is the byte array, whereas begnIndex is the beginning position within val.Example Live Demousing System; public class Demo {    public static void Main() {       byte[] arr = { 0, 20, 50, 65 };       Console.WriteLine("Array = {0} ",       BitConverter.ToString(arr));       for (int i = 1; i < arr.Length - 1; i = i + 2) {     ... Read More

Boolean.GetHashCode() Method in C# with Examples

AmitDiwan
Updated on 02-Dec-2019 11:25:31

163 Views

The Boolean.GetHashCode() method in C# is used to return the hash code for this instance.Syntaxpublic override int GetHashCode ();Example Live Demousing System; public class Demo {    public static void Main(String[] args){       string str = "JackSparrow!";       bool val = true;       char[] arr = { 'J', 'a'};       Console.WriteLine("String = "+str);       Console.WriteLine("String (after trim) = " + str.Trim(arr));       Console.WriteLine("String (Hashcode) = "+str.GetHashCode());       Console.WriteLine("Bool (Hashcode) = "+val.GetHashCode());    } }OutputString = JackSparrow! String (after trim) = ckSparrow! String (Hashcode) = -203134198 Bool (Hashcode) = 1Example Live Demousing System; public class Demo {    public static void ... Read More

What is the data type of a lambda expression in Java?

raja
Updated on 02-Dec-2019 09:14:51

1K+ Views

The lambda expressions have a very simple, precise syntax and provide flexibility to specify the datatypes for the function parameters. Its return type is a parameter -> expression body to understand the syntax, we can divide it into three parts.Parameters : These are function method parameters and match with the signature of a function defined in the functional interface. Defining the data-type of parameters is optional but the number of parameters can match with the defined signatures in the interface.Expression Body : This is either a single statement or collection of statements that represent the function definition. Defining the data-type for return ... Read More

JavaScript variables declare outside or inside loop?

Abdul Rawoof
Updated on 26-Aug-2022 11:56:41

5K+ Views

It is believed that there can be any performance-based differences when the variables are declared inside or outside the loops, but there will be no difference. As there is flexibility in any programming language to declare the variables as and when required which will be easy for the users to read and understand accordingly. So, in JavaScript too the variables can be declared inside or outside the loop as per the users ease anywhere in the function body. And even variable declarations are not commands that are executed at the run-time. If the variable is declared outside the loop, then ... Read More

How to add a class to DOM element in JavaScript?

Abdul Rawoof
Updated on 26-Aug-2022 11:55:32

1K+ Views

HTML is a mark-up language used to create the useful elements of a webpage. The DOM which means Document Object Model is used to manipulate the HTML Document. In DOM, all the elements are defined as objects. The styling in the HTML document can be done by using CSS. In here, JavaScript is being used to manipulate them. The ways in which the class can be added to a class to the DOM elements are described below. Using className If the element has a class already, then it will just add another class to it if not the element gets ... Read More

What's the difference between window.location and document.location?

Abdul Rawoof
Updated on 26-Aug-2022 11:56:00

2K+ Views

The window.location property The location property of a window (i.e. window.location) is a reference to a Location object; it represents the current URL of the document being displayed in that window. Since window object is at the top of the scope chain, so properties of the window.location object can be accessed without the window prefix. For example window.location.href can be written as location.href. The following section will show you how to get the URL of page as well as hostname, protocol, etc. using the location object property of the window object. You can use the window.location.href property to get the ... Read More

Advertisements