Retrieve Android API Version Programmatically using Kotlin

Azhar
Updated on 05-Nov-2020 14:36:13

840 Views

This example demonstrates how to retrieve Android API version programmatically using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.             Step 3 − Add the following code to src/MainActivity.ktimport android.os.Build import android.os.Bundle import android.widget.Button import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var button: Button    lateinit var textView: TextView    var androidVersion = 0    override fun onCreate(savedInstanceState: Bundle?) {     ... Read More

Draw a Line in Android Using Kotlin

Azhar
Updated on 05-Nov-2020 14:35:29

1K+ Views

This example demonstrates how to draw a line in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.ktimport android.graphics.Bitmap import android.graphics.Canvas import android.graphics.Color import android.graphics.Paint import android.os.Bundle import android.widget.Button import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var button: Button    lateinit var imageView: ImageView    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)   ... Read More

Rotate Image in ImageView by Angle on Android using Kotlin

Azhar
Updated on 05-Nov-2020 14:34:35

1K+ Views

This example demonstrates how to rotate an image in imageview by an angle on Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.Button import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var imageView: ImageView    lateinit var btnRotate: Button    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main) ... Read More

Format Decimal to Two Places or Integer in C#

Nizamuddin Siddiqui
Updated on 05-Nov-2020 13:56:19

4K+ Views

Converts the value of objects to strings based on the formats specified and inserts them into another string.Namespace:System Assembly:System.Runtime.dllEach overload of the Format method uses the composite formatting feature to include zero-based indexed placeholders, called format items, in a composite format string. At run time, each format item is replaced with the string representation of the corresponding argument in a parameter list. If the value of the argument is null, the format item is replaced with String.Empty.Exampleclass Program{    static void Main(string[] args){       int number = 123;       var s = string.Format("{0:0.00}", number);     ... Read More

Convert String to Title Case in C#

Nizamuddin Siddiqui
Updated on 05-Nov-2020 13:55:21

731 Views

Title case is any text, such as in a title or heading, where the first letter of major words is capitalized. Title case or headline case is a style of capitalization used for rendering the titles of published works or works of art in English.When using title case, all words are capitalized except for "minor" words unless they are the first or last word of the title.The current implementation of the ToTitleCase in the example yields an output string that is the same length as the input string.Example 1class Program{    static void Main(string[] args){       string myString ... Read More

Set Property Value by Reflection in C#

Nizamuddin Siddiqui
Updated on 05-Nov-2020 13:53:37

6K+ Views

The System. Reflection namespace contains classes that allow you to obtain information about the application and to dynamically add types, values, and objects to the application.Reflection objects are used for obtaining type information at runtime. The classes that give access to the metadata of a running program are in the System. Reflection namespace.Reflection allows view attribute information at runtime.Reflection allows examining various types in an assembly and instantiate these types.Reflection allows late binding to methods and properties.Reflection allows creating new types at runtime and then performs some tasks using those types.ExampleGetProperty(String)Searches for the public property with the specified name.GetType(String, Boolean)Gets ... Read More

Rethrow InnerException Without Losing Stack Trace in C#

Nizamuddin Siddiqui
Updated on 05-Nov-2020 13:52:36

1K+ Views

In c#, the throw is a keyword and it is useful to throw an exception manually during the execution of the program and we can handle those thrown exceptions using try−catch blocks based on our requirements.By using throw keyword in the catch block, we can re-throw an exception that is handled in the catch block. The re-throwing an exception is useful when we want to pass an exception to the caller to handle it in a way they want.Following is the example of re−throwing an exception to the caller using throw keyword with try-catch blocks in c#.Exampleclass Program{    static ... Read More

What is Lambda Expression in C#

Nizamuddin Siddiqui
Updated on 05-Nov-2020 13:50:58

590 Views

Lambda expression is a better way to represent an anonymous method. Both anonymous methods and Lambda expressions allow you define the method implementation inline, however, an anonymous method explicitly requires you to define the parameter types and the return type for a method.Expression lambda that has an expression as its body: (input−parameters) => expressionStatement lambda that has a statement block as its body: (input−parameters) => { }Any lambda expression can be converted to a delegate type. The delegate type to which a lambda expression can be converted is defined by the types of its parameters and return value. If ... Read More

Use Not In Query with C# LINQ

Nizamuddin Siddiqui
Updated on 05-Nov-2020 13:48:09

7K+ Views

Except operator are designed to allow you to query data which supports the IEnumerable

Difference Between AND & OR Operators in C#

Nizamuddin Siddiqui
Updated on 05-Nov-2020 13:46:18

2K+ Views

| OperatorThe | operator computes the logical OR of its operands. The result of x | y is true if either x or y evaluates to true. Otherwise, the result is false.The | operator evaluates both operands even if the left-hand operand evaluates to true, so that the operation result is true regardless of the value of the right-hand operand.|| OperatorThe conditional logical OR operator ||, also known as the "short−circuiting" logical OR operator, computes the logical OR of its operands.The result of x || y is true if either x or y evaluates to true. Otherwise, the result is ... Read More

Advertisements