System.ArrayCopyTo vs System.ArrayClone in C#

Samual Sam
Updated on 21-Jun-2020 16:53:51

306 Views

The ArrayCopyTo() method copies all the elements of the current one-dimensional Array to the specified one-dimensional Array starting at the specified destination Array index. The index is specified as a 32-bit integer.The CopyTo() method in C# is used to copy elements of one array to another array. In this method, you can set the starting index from where you want to copy from the source array.The following is an example showing the usage of CopyTo(, ) method of array class in C# −Exampleusing System; class Program {    static void Main() {       int[] arrSource = new ... Read More

What are Rvalue and Lvalue in C#

Arjun Thakur
Updated on 21-Jun-2020 16:52:48

1K+ Views

The following are the types of expressions in C# −lvalue − An expression that is an lvalue may appear as either the left-hand or right-hand side of an assignment.rvalue − An expression that is an rvalue may appear on the right- but not left-hand side of an assignment.Variables are lvalues and hence they may appear on the left-hand side of an assignment. Numeric literals are rvalues and hence they may not be assigned and cannot appear on the left-hand side.Here is a valid C# statement −int a = 100:

Write a C# Program to Solve FizzBuzz Problem

karthikeya Boyini
Updated on 21-Jun-2020 16:52:30

354 Views

The FizzBuzz problem states that −Display "Fizz" instead of the number for each multiple of 3,Display "Buzz", instead of the number for each multiple of 5.Display "FizzBuzz", instead of the number for each multiple of 5 & 3Let us see how to implement the above using C# −Exampleusing System; class Demo {    static void Main(String[] args) {       for(int i=1;i

What is a Non-Static Class in C#

Chandu yadav
Updated on 21-Jun-2020 16:51:45

1K+ Views

Non-static classes can be instantiated, whereas static classes cannot be instantiated i.e. you cannot use the new keyword to create a variable of the class type.Non-static classes can have instance method and static methods.Access the members of a static class by using the class name itself, whereas Static class is sealed.Example of non-static class −public class CalculateExample of static class −public static class Calculate

What are Virtual Functions in C++

Samual Sam
Updated on 21-Jun-2020 16:51:25

5K+ Views

The virtual keyword is useful in modifying a method, property, indexer, or event. When you have a function defined in a class that you want to be implemented in an inherited class(es), you use virtual functions. The virtual functions could be implemented differently in different inherited class and the call to these functions will be decided at runtime.The following is a virtual functionpublic virtual int area() { }Here is an example showing how to work with virtual functions −Exampleusing System; namespace PolymorphismApplication {    class Shape {       protected int width, height;           ... Read More

StringWriter vs StringReader in C#

George John
Updated on 21-Jun-2020 16:44:42

398 Views

StringReader and StringWriter derive from TextReader and TextWriterStringWriter is used for writing into a string buffer. It implements a TextWriter for writing information to a string.For StringWriter −ExampleStringWriter sWriter = new StringWriter(); while(true) {    myChar = strReader.Read();    if(myChar == -1) break;    convertedChar = Convert.ToChar(myChar);    if(convertedChar == '.') {       strWriter.Write(".");       sReader.Read();       sReader.Read();    }else {       sWriter.Write(convertedChar);    } } }StringReader to read a string −ExampleStringBuilder sbuilder = new StringBuilder(); // append sbuilder.AppendLine("Line one characters"); sbuilder.AppendLine("Line two characters"); sbuilder.AppendLine("Line three characters"); // ... Read More

Copy Collection to Array Using Chash

Ankith Reddy
Updated on 21-Jun-2020 16:42:08

182 Views

To copy a collection to an array, firstly set it −List < string > list1 = new List < string > (); list1.Add("Car"); list1.Add("Bus"); list1.Add("Motorbike"); list1.Add("Train");Now declare a string array and use the CopyTo() method to copy −string[] arr = new string[20]; list1.CopyTo(arr);Let us see the complete code to copy collection to array −Exampleusing System; using System.Collections.Generic; using System.Linq; public class Demo {    public static void Main() {       List < string > list1 = new List < string > ();       list1.Add("Car");       list1.Add("Bus");       list1.Add("Motobike");       ... Read More

User View vs System View in Operating System

Amit Diwan
Updated on 21-Jun-2020 16:37:44

22K+ Views

An operating system is a construct that allows the user application programs to interact with the system hardware. Operating system by itself does not provide any function but it provides an atmosphere in which different applications and programs can do useful work.The operating system can be observed from the point of view of the user or the system. This is known as the user view and the system view respectively. More details about these are given as follows −User ViewThe user view depends on the system interface that is used by the users. The different types of user view experiences ... Read More

Static vs Non-Static Method in C#

karthikeya Boyini
Updated on 21-Jun-2020 16:36:07

1K+ Views

Declare a member function as static. Such functions can access only static variables. The static functions exist even before the object is created.A static class cannot be instantiated and can only contain static members.Static methods is set using static keyword −public static int getNum() {    return num; }The following example demonstrates the use of static and non-static methods −Exampleusing System; namespace StaticVarApplication {    class StaticVar {       public static int num;       public void count() {          num++;       }       public static int ... Read More

String Format for Double in C#

Chandu yadav
Updated on 21-Jun-2020 16:35:00

2K+ Views

Use the static method String.Format for form double string format in C#.For three decimal places −String.Format("{0:0.000}", 987.383); String.Format("{0:0.000}", 987.38); String.Format("{0:0.000}", 987.7899);For thousands separator −String.Format("{0:0,0.0}", 54567.46); String.Format("{0:0,0}", 54567.46);To format string −Exampleusing System; class Demo {    public static void Main(String[] args) {       Console.WriteLine("Three decimal places...");           Console.WriteLine( String.Format("{0:0.000}", 987.383));       Console.WriteLine( String.Format("{0:0.000}", 987.38));       Console.WriteLine(String.Format("{0:0.000}", 987.7899));           Console.WriteLine("Thousands Separator...");       Console.WriteLine(String.Format("{0:0,0.0}", 54567.46));       Console.WriteLine(String.Format("{0:0,0}", 54567.46));    } }

Advertisements