GetMember Method in C#

AmitDiwan
Updated on 11-Nov-2019 05:47:30

252 Views

The Type.GetMember() method in C# is used to get the specified members of the current Type.SyntaxFollowing is the syntax −public System.Reflection.MemberInfo[] GetMember (string name); public virtual System.Reflection.MemberInfo[] GetMember (string name, System.Reflection.BindingFlags bindingAttr);ExampleLet us now see an example to implement the Type.GetMember() method −using System; using System.Reflection; public class Demo {    public static void Main(){       Type type = typeof(Subject);       try {          FieldInfo fieldInfo = type.GetField("SubName");          MemberInfo[] info = type.GetMember("SubName");          Console.Write("Members = ");          for (int i = 0; i ... Read More

DateTime AddMinutes Method in C#

AmitDiwan
Updated on 11-Nov-2019 05:43:56

7K+ Views

The DateTime.AddMinutes() method in C# is used to add the specified number of minutes to the value of this instance. It returns the new DateTime.SyntaxFollowing is the syntax −public DateTime AddMinutes (double m);Above, m are the minutes to be added. If a negative value is added, then the minutes will get subtracted.ExampleLet us now see an example to implement the DateTime.AddMinutes() method −using System; public class Demo {    public static void Main(){       DateTime d1 = new DateTime(2019, 09, 10, 5, 15, 25);       DateTime d2 = d1.AddMinutes(25);       System.Console.WriteLine("Initial DateTime = {0:dd} ... Read More

Add Milliseconds to DateTime in C#

AmitDiwan
Updated on 11-Nov-2019 05:42:03

2K+ Views

The DateTime.AddMilliseconds() method in C# is used to adds the specified number of milliseconds to the value of this instance. This method returns a new DateTime.SyntaxFollowing is the syntax −public DateTime AddMilliseconds (double mSec);Above, mSec is the milliseconds to be added.ExampleLet us now see an example to implement the DateTime.AddMilliseconds() method −using System; public class Demo {    public static void Main(){       DateTime d1 = new DateTime(2019, 11, 10, 5, 0, 25);       DateTime d2 = d1.AddMilliseconds(1000);       System.Console.WriteLine("Initial DateTime = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d1);       System.Console.WriteLine("New DateTime (After adding ... Read More

Math Sinh Method in C#

AmitDiwan
Updated on 11-Nov-2019 05:40:28

105 Views

The Math.Sinh() method in C# is used to return the hyperbolic sine of a specified angle.SyntaxFollowing is the syntax −public static double Sinh(double val)Above, the argument value is the angle.ExampleLet us now see an example to implement the Math.Sinh() method −using System; public class Demo {    public static void Main(){       double val1 = 30.0;       double val2 = 45.0;       Console.WriteLine(Math.Sinh(val1));       Console.WriteLine(Math.Sinh(val2));    } }OutputThis will produce the following output −5343237290762.23 1.74671355287425E+19ExampleLet us see another example to implement the Math.Sinh() method −using System; public class Demo {    public ... Read More

Math Sin Method in C#

AmitDiwan
Updated on 08-Nov-2019 11:21:08

771 Views

The Math.Sin() method in C# is used to return the sine of a specified angle.SyntaxFollowing is the syntax −public static double Sin (double val);Above, the argument value is an angle.ExampleLet us now see an example to implement Math.Sin() method −using System; public class Demo {    public static void Main(){       double val1 = 30.0;       Console.WriteLine(Math.Sin( (val1 * (Math.PI)) / 180 ));    } }OutputThis will produce the following output −0.5ExampleLet us see another example to implement Math.Sin() method −using System; public class Demo {    public static void Main(){       double val1 ... Read More

MySQL Number String Formatting to Pad Zeros on the Left

AmitDiwan
Updated on 08-Nov-2019 11:20:41

334 Views

Let us first create a table −mysql> create table DemoTable1369     -> (     -> BatchId varchar(20)     -> ); Query OK, 0 rows affected (0.46 sec)Insert some records in the table using insert command. We have inserted numbers here separated by a slash −mysql> insert into DemoTable1369 values('19/5'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1369 values('19/78'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1369 values('19/567'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1369 values('19/1234'); Query OK, 1 row affected (0.11 sec)Display all records from the table ... Read More

Math Sign Method in C#

AmitDiwan
Updated on 08-Nov-2019 11:19:12

1K+ Views

The Math.Sign() method in C# is used to return an integer that indicates the sign of a number.MethodsThe Math.Sign() overloads the following methods −Math.Sign(Int16) Math.Sign(Int32) Math.Sign(Int64) Math.Sign(SByte) Math.Sign(Single) Math.Sign(Decimal) Math.Sign(Double)ExampleLet us now see an example to implement Math.Sign() method −using System; public class Demo {    public static void Main(){       short val1 = 1;       int val2 = 20;       long val3 = -3545465777;       Console.WriteLine("Short Value = " + val1);       Console.WriteLine("Sign (Short Value) = " + getSign(Math.Sign(val1)));       Console.WriteLine("Int32 value = " + val2);   ... Read More

Append Stars Based on String Length in MySQL Query

AmitDiwan
Updated on 08-Nov-2019 11:17:51

268 Views

For this, you can use RPAD(). Let us first create a table −mysql> create table DemoTable1626     -> (     -> Name varchar(20)     -> ); Query OK, 0 rows affected (0.37 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1626 values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1626 values('Bob'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable1626 values('Robert'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select * from DemoTable1626; This will produce the following output −+--------+ ... Read More

Adding Dash Between Spaces in Field Name in MySQL

AmitDiwan
Updated on 08-Nov-2019 11:16:51

456 Views

You can use REPLACE() for this. Let us first create a table −mysql> create table DemoTable1625     -> (     -> FullName varchar(20)     -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1625 values('John Doe'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1625 values('Adam Smith'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1625 values('John Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1625 values('Carol Taylor'); Query OK, 1 row affected (0.14 sec)Display all records from the ... Read More

Math.Round Method in C#

AmitDiwan
Updated on 08-Nov-2019 11:16:22

8K+ Views

The Math.Round() method in C# rounds a value to the nearest integer or to the specified number of fractional digits.MethodsThe following are the methods overloaded by Math.Round() −Math.Round(Double) Math.Round(Double, Int32) Math.Round(Double, Int32, MidpointRounding) Math.Round(Double, MidpointRounding) Math.Round(Decimal) Math.Round(Decimal, Int32) Math.Round(Decimal, Int32, MidpointRounding) Math.Round(Decimal, MidpointRounding)ExampleLet us now see an example to implement Math.Round() method i.e. Math.Round(Decimal) −using System; public class Demo {    public static void Main(){       Decimal val1 = 78.12m;       Decimal val2 = 30.675m;       Console.WriteLine("Decimal Value = " + val1);       Console.WriteLine("Rounded value = " + Math.Round(val1));       ... Read More

Advertisements