Convert the dateTime to toString that results in converting the DateTime to “YYYYMMDDHHMMSS” formatThere are also other formats that the dateTime can be convertedMM/dd/yyyy 08/22/2020dddd, dd MMMM yyyy Tuesday, 22 August 2020dddd, dd MMMM yyyy HH:mm Tuesday, 22 August 2020 06:30dddd, dd MMMM yyyy hh:mm tt Tuesday, 22 August 2020 06:30 AMdddd, dd MMMM yyyy H:mm Tuesday, 22 August 2020 6:30dddd, dd MMMM yyyy h:mm tt Tuesday, 22 August 2020 6:30 AMdddd, dd MMMM yyyy HH:mm:ss Tuesday, 22 August 2020 06:30:07MM/dd/yyyy HH:mm 08/22/2020 06:30MM/dd/yyyy hh:mm tt 08/22/2020 06:30 AMMM/dd/yyyy H:mm 08/22/2020 6:30MM/dd/yyyy h:mm tt 08/22/2020 6:30 AMMM/dd/yyyy HH:mm:ss 08/22/2020 06:30:07Example Live ... Read More
A power of 2 is a number of the form 2n where n is an integerThe result of exponentiation with number two as the base and integer n as the exponent.n2n01122438416532Example 1 Live Democlass Program { static void Main() { Console.WriteLine(IsPowerOfTwo(9223372036854775809)); Console.WriteLine(IsPowerOfTwo(4)); Console.ReadLine(); } static bool IsPowerOfTwo(ulong x) { return x > 0 && (x & (x - 1)) == 0; } }OutputFalse TrueExample 2 Live Democlass Program { static void Main() { Console.WriteLine(IsPowerOfTwo(9223372036854775809)); Console.WriteLine(IsPowerOfTwo(4)); Console.ReadLine(); } static bool IsPowerOfTwo(ulong n) { if (n == 0) return false; while (n != 1) { if (n % 2 != 0) return false; n = n / 2; } return true; } }OutputFalse True
Deep copies duplicate everything. A deep copy of a collection is two collections with all of the elements in the original collection duplicatedDeep Copy is used to make a complete deep copy of the internal reference types.In another words a deep copy occurs when an object is copied along with the objects to which it refersExample Live Democlass DeepCopy { public int a = 10; } class Program { static void Main() { //Deep Copy DeepCopy d = new DeepCopy(); d.a = 10; DeepCopy d1 = new ... Read More
The Enum Flags is used to take an enumeration variable and allow it hold multiple values. It should be used whenever the enum represents a collection of flags, rather than representing a single valueUse the FlagsAttribute for an enumeration only if a bitwise operation (AND, OR, EXCLUSIVE OR) is to be performed on a numeric value.Define enumeration constants in powers of two, that is, 1, 2, 4, 8, and so on. This means the individual flags in combined enumeration constants do not overlap.Example Live Democlass Program { [Flags] enum SocialMediaFlags { None = 0, Facebook = 1, Twitter = ... Read More
Typeof()The type takes the Type and returns the Type of the argument.GetType()The GetType() method of array class in C# gets the Type of the current instance.isThe "is" keyword is used to check if an object can be casted to a specific type. The return type of the operation is Boolean.Example Live Democlass Demo { } class Program { static void Main() { var demo = new Demo(); Console.WriteLine($"typeof { typeof(Demo)}"); Type tp = demo.GetType(); Console.WriteLine($"GetType {tp}"); if (demo is Demo) { ... Read More
Singleton Pattern belongs to Creational type patternSingleton design pattern is used when we need to ensure that only one object of a particular class is Instantiated. That single instance created is responsible to coordinate actions across the application.As part of the Implementation guidelines we need to ensure that only one instance of the class exists by declaring all constructors of the class to be private. Also, to control the singleton access we need to provide a static property that returns a single instance of the object.ExampleSealed ensures the class being inherited and object instantiation is restricted in the derived classPrivate ... Read More
StaticStatic is a keywordStatic classes can contain only static membersStatic objects are stored in stack.Static cannot implement interfaces, inherit from other classesSingletonSingleton is a design patternSingleton is an object creational pattern with one instance of the classSingleton can implement interfaces, inherit from other classes and it aligns with the OOPS conceptsSingleton object can be passed as a referenceSingleton supports object disposalSingleton object is stored on heapSingleton objects can be clonedSingleton objects are stored in Heap
File handling is an important part of any web application.Python has several functions for creating, reading, updating, and deleting files.To write to an existing file, you must add a parameter to the open()function −"a" − Append − will append to the end of the file"w" − Write − will overwrite any existing contentExampleimport os # list the files in directory lis = os.listdir('D:\python' '\data_files\data_files') print(lis) tgt = os.listdir('D:\python' '\data_files\target_file') file_dir ='D:\python\data_files\data_files' out_file = r'D:\python\data_files\target_file\master.txt' ct = 0 print('target file :', tgt) try: # check for if file exists # if yes delete the file # otherwise ... Read More
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.Example#applying pseudocolor # importing pyplot and image from matplotlib import matplotlib.pyplot as plt import matplotlib.image as img # reading png image im = img.imread('imR.png') # applying pseudocolor # default value of colormap is used. lum = im[:, :, 0] # show image plt.imshow(lum) #colorbar # importing pyplot and image from matplotlib import matplotlib.pyplot as plt import matplotlib.image as img # reading png image im = ... Read More
Python Pandas is a data analysis library. It can read, filter and re-arrange small and large datasets and output them in a range of formats including Excel.Pandas writes Excel files using the XlsxWriter modules.XlsxWriter is a Python module for writing files in the XLSX file format. It can be used to write text, numbers, and formulas to multiple worksheets. Also, it supports features such as formatting, images, charts, page setup, auto filters, conditional formatting and many others.Example# import pandas as pd import pandas as pd # Create some Pandas dataframes from some data. df1 = pd.DataFrame({'Data': [11, 12, 13, 14]}) df2 = pd.DataFrame({'Data': [21, ... Read More