Programming Articles

Page 792 of 2544

C# Linq ElementAt Method

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 340 Views

The ElementAt() method in C# to get elements at specified index position.Firstly, set the string array.string[] str = { "Jack", "Pat", "David"};Now, to get the element at a particular index, use the ElementAt() method as shown in the following example −Exampleusing System.IO; using System; using System.Linq; class Program {    static void Main() {       string[] str = { "Jack", "Pat", "David"};       Random r = new Random(DateTime.Now.Second);       // to generate random string       string res = str.AsQueryable().ElementAt(r.Next(0, str.Length));       Console.WriteLine("Random Name = '{0}'", res);    } }OutputRandom Name = 'Jack'

Read More

Sortable ("s") Format Specifier in C#

Arjun Thakur
Arjun Thakur
Updated on 11-Mar-2026 546 Views

The Sortable standard format specifier represents a custom date and time format string.The format string is defined by the DateTimeFormatInfo.SortableDateTimePattern property.The custom format string.yyyy'-'MM'-'dd'T'HH':'mm':'ssExampleusing System; class Demo {    static void Main() {       DateTime date = new DateTime(2018, 9, 5, 2, 12, 40);       Console.WriteLine(date.ToString("s"));    } }Output2018-09-05T02:12:40

Read More

Write a power (pow) function using C++

Samual Sam
Samual Sam
Updated on 11-Mar-2026 2K+ Views

The power function is used to find the power given two numbers that are the base and exponent. The result is the base raised to the power of the exponent.An example that demonstrates this is as follows −Base = 2 Exponent = 5 2^5 = 32 Hence, 2 raised to the power 5 is 32.A program that demonstrates the power function in C++ is given as follows −Example#include using namespace std; int main(){    int x, y, ans = 1;    cout > x;    cout > y;    for(int i=0; i

Read More

C# Linq First() Method

Samual Sam
Samual Sam
Updated on 11-Mar-2026 3K+ Views

Use the First() method to get the first element from an array.Firstly, set an array.int[] arr = {20, 40, 60, 80 , 100};Now, use the Queryable First() method to return the first element.arr.AsQueryable().First();The following is the entire example.Exampleusing System; using System.Linq; using System.Collections.Generic; class Program {    static void Main() {       int[] arr = {20, 40, 60, 80 , 100};       // getting the first element       int res = arr.AsQueryable().First();       Console.WriteLine(res);    } }Output20

Read More

How to print a variable name in C?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

The following is an example to print variable name.Example#include #define VariableName(name) #name int main() {    int name;    char ch;    printf("The variable name : %s", VariableName(name));    printf("The variable name : %s", VariableName(ch));    return 0; }OutputThe variable name : name The variable name : chIn the above program, the variable names are printed by defining the method before main()#define VariableName(name) #nameTwo variables of different datatypes are declared. By using the defined function, variable names are printed.int name; char ch; printf("The variable name : %s", VariableName(name)); printf("The variable name : %s", VariableName(ch));

Read More

Create and demonstrate an immutable collection in Java

Anvi Jain
Anvi Jain
Updated on 11-Mar-2026 243 Views

In order to create and demonstrate an immutable collection in Java, we use the unmodifiableCollection() method. This method returns an unmodifiable and immutable view of the collection.Declaration − The java.util.Collections.unmodifiableCollection() method is declared as follows -public static Collection unmodifiableCollection(Collection

Read More

C# Math.DivRem Method

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 234 Views

Use the Math.DivRem method to calculate the quotient of two numbers and return the remainder.Firstly, set dividend and divisor.// dividend long dividend = 30; // divisor long divisor = 7;Now, use the DivRem method.long quotient = Math.DivRem(dividend, divisor, out rem);Exampleusing System; using System.Globalization; class Demo {    static void Main() {       // remainder       long rem;       // dividend       long dividend = 98;       // divisor       long divisor = 9;       long quotient = Math.DivRem(dividend, divisor, out rem);       Console.WriteLine("{0} \ {1} = {2} and remainder = {3}", dividend, divisor, quotient, rem);    } }Output98 \ 9 = 10 and remainder = 8

Read More

Copy characters from string into char Array in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

Let’s say we have the following string.String str = "Demo Text!";To copy some part of the above string, use the getChars() method.// copy characters from string into chArray =str.getChars( 0, 5, chArray, 0 );The following is an example to copy characters from string into char Array in Java.Examplepublic class Demo {    public static void main(String[] args) {       String str = "Demo Text!";       char chArray[] = new char[ 5 ];       System.out.println("String: "+str);       // copy characters from string into chArray       str.getChars( 0, 5, chArray, 0 ); ...

Read More

Represent Int32 as a String in C#

Samual Sam
Samual Sam
Updated on 11-Mar-2026 332 Views

Int32 represents a 32-bit signed integer. To represent it as a string, use the ToString() method.Firstly, declare and initialize an Int32 variable.int val = 1023;Now, represent it as a string.val.ToString()Let us see the complete example.Exampleusing System; class Demo {    static void Main() {       int val = 1023;       Console.Write("Integer converted to string = "+val.ToString());    } }OutputInteger converted to string = 1023

Read More

How to schedule tasks in Java to run for repeated fixed-rate execution, beginning after the specified delay

Smita Kapse
Smita Kapse
Updated on 11-Mar-2026 498 Views

One of the methods of the Timer class is void scheduleAtFixedRate(TimerTask task, long delay, long period). This method schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.In fixed-rate execution, each execution is scheduled with respect to the scheduled run time of the initial execution. Fixed-rate execution is apt for repetitive activities that are respond to absolute time. Likewise, fixed-rate execution is appropriate for scheduling multiple repeating timer tasks that must remain in sync.Declaration − The java.util.Time.scheduleAtFixedRate(TimerTask task, long delay, long period) method is declared as follows −public void scheduleAtFixedRate(TimerTask task, long delay, long period)Here, task is ...

Read More
Showing 7911–7920 of 25,433 articles
« Prev 1 790 791 792 793 794 2544 Next »
Advertisements