Get Creation Time of a File in C#

karthikeya Boyini
Updated on 22-Jun-2020 14:43:02

2K+ Views

To get the creation time of a file in C#, use the CreationTime() method.For this, use the FileInfo as well as DateTime classes.Create an object of each −FileInfo file = new FileInfo("new.txt"); DateTime dt = file.CreationTime;Let us see the complete code −Example Live Demousing System.IO; using System; public class Program {    public static void Main() {       using (StreamWriter sw = new StreamWriter("qa.txt")) {          sw.WriteLine("Questions and Answers!");       }       FileInfo file = new FileInfo("qa.txt");       // file creation time       DateTime dt = file.CreationTime;       Console.WriteLine(dt);    } }Output9/5/2018 5:20:03 AM

Optional Arguments in JavaScript Functions

Daniol Thomas
Updated on 22-Jun-2020 14:42:54

277 Views

To declare optional function parameters in JavaScript, use the “default” arguments.ExampleYou can try to run the following code to declare optional parameters −                    // default is set to 1          function inc(val1, inc = 1) {             return val1 + inc;          }          document.write(inc(10,10));          document.write("");          document.write(inc(10));          

Lowercase Suffixes in C#

Samual Sam
Updated on 22-Jun-2020 14:42:40

172 Views

Set lowercase suffixes for literals such as u, l, ul, f, etc.// l for long long a = 29876l;It can be used on literal numbers as well. It tells the compiler that the literal is of a specific type.The following is an example −Example Live Demousing System.IO; using System; public class Program {    public static void Main() {       long a = 29876l;       float b = 95.10f;       Console.WriteLine(a);       Console.WriteLine(b);    } }On running the above example, you will get the following output. With that, you will also get a ... Read More

Define JavaScript Function Using Function Constructor

Nikitha N
Updated on 22-Jun-2020 14:42:23

224 Views

The Function() constructor expects any number of string arguments. The last argument is the body of the function - it can contain arbitrary JavaScript statements, separated from each other by semicolons.ExampleYou can try to run the following code to invoke a function with new Function Constructor −                    var func = new Function("x", "y", "return x*y;");          function multiplyFunction(){             var result;             result = func(15,35);             document.write ( result );          }                     Click the following button to call the function                          

Literal Number Suffixes in C#

karthikeya Boyini
Updated on 22-Jun-2020 14:42:15

470 Views

To specify number types, use suffixes in C#. Literal number suffixes are numeric suffixes.For example, for long type −// long suffix long val1 = 29345L;For double type −// double suffix double val2 = 297.325D; Console.WriteLine(val2);Let us see more examples −Example Live Demousing System.IO; using System; public class Program {    public static void Main() {       // long suffix       long val1 = 29345L;       Console.WriteLine(val1);       // decimal suffix       decimal val5 = 3245.5678M;       Console.WriteLine(val5);       // double suffix       double val2 = 297.325D;       Console.WriteLine(val2);       // float suffix       float val3 = 250.35F;       Console.WriteLine(val3);       // unsigned suffix       uint val4 = 3456U;       Console.WriteLine(val4);    } }Output29345 3245.5678 297.325 250.35 3456

ElementAt Method in C#

Samual Sam
Updated on 22-Jun-2020 14:41:37

4K+ Views

ElementAt() is a System.Linq method in C# that is used to get and display element at a particular index.The following is our string array −string[] arr = { "One", "Two", "Three", "Four", "Five" };Now to get an element at index 0, use the ElementAt() method −arr.ElementAt(0);The following is the complete code −Example Live Demousing System.IO; using System; using System.Linq; public class Demo {    public static void Main() {       string[] arr = { "One", "Two", "Three", "Four", "Five" };       // displaying element at index 0       string res = arr.ElementAt(0);       Console.WriteLine(res);    } }OutputOne

C# Program to Skip Initial Elements in an Array

karthikeya Boyini
Updated on 22-Jun-2020 14:41:15

3K+ Views

If you want to skip a number of elements in an array, then use the Skip() method in C#.Let’s say the following is our array −int[] arr = { 24, 40, 55, 62, 70, 82, 89, 93, 98 };Now to skip first four elements −var ele = arr.Skip(4);Let us see the complete example −Example Live Demousing System.IO; using System; using System.Linq; public class Demo {    public static void Main() {       int[] arr = { 24, 40, 55, 62, 70, 82, 89, 93, 98 };       Console.WriteLine("Initial Array...");       foreach (var res in arr) ... Read More

SkipWhile Method in C#

Samual Sam
Updated on 22-Jun-2020 14:40:31

373 Views

SkipWhile skips an element when a condition is matched.For example, use the following if you want to skip all even elements −ele => ele %2 == 0The following is an example wherein all the even elements are skipped and only the odd elements are displayed −Example Live Demousing System.IO; using System; using System.Linq; public class Demo {    public static void Main() {       int[] arr = { 20, 35, 55 };       Console.WriteLine("Initial array...");       foreach (int value in arr) {          Console.WriteLine(value);       }       // ... Read More

Find Largest Element from Array Using Lambda Expressions in C#

karthikeya Boyini
Updated on 22-Jun-2020 14:39:54

657 Views

Declare an array −int[] arr = { 10, 90, 20, 19, 99, 57 };Now to get the largest element from an array, use Max() method with lambda expressions −arr.Max());Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       int[] arr = { 10, 90, 20, 19, 99, 57 };       Console.WriteLine(arr.Max(element => Math.Abs(element)));    } }Output99

Self-Invoking Anonymous Functions in JavaScript

Rishi Rathor
Updated on 22-Jun-2020 14:39:42

482 Views

In JavaScript, the functions wrapped with parenthesis are called “Immediately Invoked Function Expressions" or "Self Executing Functions.The purpose of wrapping is to the namespace and control the visibility of member functions. It wraps the code inside a function scope and decreases clashing with other libraries. This is what we call Immediately Invoked Function Expression (IIFE) or Self Executing Anonymous Function.SyntaxHere’s the syntax −(function() {    // code })();As you can see above, the following pair of parentheses converts the code inside the parentheses into an expression −function(){...}In addition, the next pair, i.e. the second pair of parentheses continues the operation. ... Read More

Advertisements