Convert To SByte Method in C#

karthikeya Boyini
Updated on 23-Jun-2020 07:45:44

309 Views

Convert a specified value to an 8-bit signed integer i.e. SByte.It is a signed 8-bit integer data type which stores value between -128 to 127.Let us see an example. We have a double variable.double doubleNum = -19.9;Now, let us convert it to SByte.sbyte res; res = Convert.ToSByte(doubleNum);Example Live Demousing System; public class Demo {    public static void Main() {       double doubleNum = -19.9;       sbyte res;       res = Convert.ToSByte(doubleNum);       Console.WriteLine("Converted {0} to {1}", doubleNum, res);    } }OutputConverted -19.9 to -20

Search a Carriage Return Character with JavaScript RegExp

Ayyan
Updated on 23-Jun-2020 07:45:25

699 Views

To find carriage return character with JavaScript Regular Expression, use the following −\rExampleYou can try to run the following code to find a carriage return character. It returns the position where the carriage return (\r) character is found −           JavaScript Regular Expression                        var myStr = "100% \r Responsive!";          var reg = /\r/;          var match = myStr.search(reg);                    document.write(match);          

Remove First Occurrence of a Node in a Linked List - C# Program

George John
Updated on 23-Jun-2020 07:45:07

141 Views

The following is our LinkedList list with nodes.string [] students = {"Katie", "Jennifer", "Amy", "Vera"}; LinkedList list = new LinkedList(students);Now let us remove a node with the string element “Vera”.For that, use Remove() method.list.Remove("Vera");Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       string [] students = {"Katie", "Jennifer", "Amy", "Vera"};       LinkedList list = new LinkedList(students);       foreach (var stu in list) {          Console.WriteLine(stu);       }       // removing a node       list.Remove("Vera");       Console.WriteLine("LinkedList after removing ... Read More

Represent Int32 as a Hexadecimal String in C#

Samual Sam
Updated on 23-Jun-2020 07:44:35

5K+ Views

To represent Int32 as a Hexadecimal string in C#, use the ToString() method and set the base as the ToString() method’s second parameter i.e. 16 for Hexadecimal.Int32 represents a 32-bit signed integer.Firstly, set an Int32 variable.int val = 9898;Now, convert it to a hexadecimal string by including 16 as the second parameter.Convert.ToString(val, 16)Example Live Demousing System; class Demo {    static void Main() {       int val = 9898;       Console.WriteLine("Integer: "+val);       Console.Write("Hex String: "+Convert.ToString(val, 16));    } }OutputInteger: 9898 Hex String: 26aa

C# Program to Return a Collection with Repeated Elements

Chandu yadav
Updated on 23-Jun-2020 07:44:12

343 Views

To return a collection with repeated elements in C#, use Enumerable.Repeat method.It is part of System.Linq namespace.Let’s say you need to repeat a number twice, for that set the number and the frequency of repetition.Enumerable.Repeat(50, 2);Now assign it to a variable and display it.Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       // repeating element 50, two times       var num = Enumerable.Repeat(50, 2);       // displayig repeating elements       foreach (int ele in num) {          Console.WriteLine(ele);       }    } }Output50 50

Convert ToInt32 Method in C#

karthikeya Boyini
Updated on 23-Jun-2020 07:43:49

7K+ Views

Use the Convert.ToInt32() method to convert a specified value to a 32-bit signed integer.Let us take a double variable.double doubleNum = 11.53;Now, we will convert it to Int32 using the Convert.ToInt32 method.int intNum; ntNum = Convert.ToInt32(doubleNum);Example Live Demousing System; public class Demo {    public static void Main() {       double doubleNum = 11.53;       int intNum;       intNum = Convert.ToInt32(doubleNum);       Console.WriteLine("Converted {0} to {1}", doubleNum, intNum);    } }OutputConverted 11.53 to 12

LinkedList addFirst Method in C#

Arjun Thakur
Updated on 23-Jun-2020 07:43:27

765 Views

In a Linked List, if you want to add a node at the first position, use AddFirst method.Let’s first set a LinkedList.string [] students = {"Jenifer", "Angelina", "Vera"}; LinkedList list = new LinkedList(students);Now, to add an element as a first node, use AddFirst() method.List.AddFirst(“Natalie”);Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       string [] students = {"Jenifer", "Angelina", "Vera"};       LinkedList list = new LinkedList(students);       foreach (var stu in list) {          Console.WriteLine(stu);       }       // add a node   ... Read More

Implicit Conversion from Int16 to Decimal in C#

Samual Sam
Updated on 23-Jun-2020 07:42:46

255 Views

The short type represents a 16-bit signed integer i.e. Int16.To implicitly convert a 16-bit signed integer to a Decimal, firstly set a short value.short val = -32768;To convert short to decimal, assign the value.dec = val;Let us see another example.Example Live Demousing System; public class Demo {    public static void Main() {       short val = -32768;       decimal dec;       Console.WriteLine("Implicit conversion from Int16 to Decimal");       dec = val;       Console.WriteLine("Decimal : "+dec);    } }OutputImplicit conversion from Int16 to Decimal Decimal : -32768

Implicit Conversion from Char to Decimal in C#

Ankith Reddy
Updated on 23-Jun-2020 07:42:22

2K+ Views

To implicitly convert char to a Decimal, firstly set a char.char c = 'p';To convert char to decimal, assign the value.decimal dec; dec = c;Let us see the above example.Example Live Demousing System; public class Demo {    public static void Main() {       char c = 'p';       decimal dec;       Console.WriteLine("Implicit conversion from Char to Decimal");       dec = c;       Console.WriteLine("Decimal : "+dec);    } }OutputImplicit conversion from Char to Decimal Decimal : 112

Add Node Before Given Node in a Linked List

Arjun Thakur
Updated on 23-Jun-2020 07:41:56

267 Views

Declare a LinkedList and add nodes to it.string [] students = {"Tim", "Jack", "Henry", "David", "Tom"}; LinkedList list = new LinkedList(students);Let us add a new node.var newNode = list.AddLast("Kevin");Now, to add a node before the given node, use the AddBefore() method.list.AddBefore(newNode, "Matt");Let us now see the complete code.Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       string [] students = {"Tim", "Jack", "Henry", "David", "Tom"};       LinkedList list = new LinkedList(students);       foreach (var stu in list) {          Console.WriteLine(stu);       }     ... Read More

Advertisements