Csharp Articles

Page 163 of 196

Command Line arguments in C#

Samual Sam
Samual Sam
Updated on 20-Jun-2020 3K+ Views

If you want to pass arguments by command line, then use command line arguments in C# −When we create a program in c#, static void main is used and we can see the arguments in it .class HelloWorld {    static void Main(string[] args) {       /* my first program in C# */       Console.WriteLine("Hello World");       Console.ReadKey();    }The string[] args is a variable that has all the values passed from the command line as shown above.Now to print those arguments, let’s say we have an argument, “One” −Console.WriteLine("Length of the arguments: "+args.Length); ...

Read More

How to declare member function in C# interface?

karthikeya Boyini
karthikeya Boyini
Updated on 20-Jun-2020 255 Views

To declare member functions in interfaces in C# −public interface InterfaceName {    // interface members    void InterfaceMemberOne();    double InterfaceMembeTwo();    void InterfaceMemberThree() } public class ClassName: InterfaceName {    void InterfaceMemberOne() {       // interface member    } }Above we saw our interface members are −void InterfaceMemberOne(); double InterfaceMembeTwo(); void InterfaceMemberThree()We have then used it in the class for implementing interface −public class ClassName: InterfaceName {    void InterfaceMemberOne() {       // interface member    } }

Read More

How to use RightShift Operators in C#?

Samual Sam
Samual Sam
Updated on 20-Jun-2020 188 Views

The left operands value is moved right by the number of bits specified by the right operand in Right Shift Operator.Let us see an example of Right Shift operator in C# −using System; namespace OperatorsAppl {    class Program {       static void Main(string[] args) {          int a = 60; /* 60 = 0011 1100 */          int b = 0;          b = a >> 2; /* 15 = 0000 1111 */          Console.WriteLine("Right Shift Operator - Value of b is {0}", b);          Console.ReadLine();       }    } }Above, the value of a is 60 i.e. 0011 1100 in binary.Set right shift operator as shown in the above example. This shifts the bits to the right twice −a >> 2Now the output will be 15 i.e.15 = 0000 1111

Read More

What are control statements in C#?

Samual Sam
Samual Sam
Updated on 20-Jun-2020 6K+ Views

The flow of program control is specified by control statements in C#. It includes the following −if statementAn if statement consists of a boolean expression followed by one or more statements.The following is the syntax −if(boolean_expression) {    /* statement(s) will execute if the boolean expression is true */ }if-else statementAn if statement can be followed by an optional else statement, which executes when the boolean expression is false.The following is the syntax −if(boolean_expression) {    /* statement(s) will execute if the boolean expression is true */ } else {    /* statement(s) will execute if the boolean expression is ...

Read More

C# Program to find whether the Number is Divisible by 2

Samual Sam
Samual Sam
Updated on 19-Jun-2020 8K+ Views

If the remainder of the number when it is divided by 2 is 0, then it would be divisible by 2. Let's say our number is 5, we will check it using the following if-else − // checking if the number is divisible by 2 or not if (num % 2 == 0) { Console.WriteLine("Divisible by 2 "); } else { Console.WriteLine("Not divisible by 2"); } Example The following is an example to find whether the number is divisible by 2 or not. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo { ...

Read More

Common Language Runtime (CLR) in C#.NET

Samual Sam
Samual Sam
Updated on 19-Jun-2020 6K+ Views

Common Language Runtime (CLR) manages the execution of .NET programs. The just-in-time compiler converts the compiled code into machine instructions. This is what the computer executes.The services provided by CLR include memory management, exception handling, type safety, etc.Let us see the features of Common Language Runtime (CLR) in C#:ComponentsComponents in other languages can be easily worked upon with CLR.ThreadingThe CLR provides support for threads to create multithreaded applications.Class Library SupportIt has built-in types and libraries for assemblies, threading, memory management, etc.DebuggingCLR makes code debugging easier.Garbage CollectionIt provides automatic garbage collection in C#.

Read More

C# program to Illustrate Upper Triangular Matrix

Samual Sam
Samual Sam
Updated on 19-Jun-2020 598 Views

For the upper triangular matrix, set all the elements below the main diagonal to zero. Set the following condition − if (i

Read More

C# Program to perform all Basic Arithmetic Operations

Samual Sam
Samual Sam
Updated on 19-Jun-2020 10K+ Views

Basic Arithmetic Operators in C#, include the following − Operator Description + Adds two operands - Subtracts the second operand from the first * Multiplies both operands / Divides the numerator by de-numerator % Modulus Operator and remainder of after an integer division ++ Increment operator increases integer value by one -- Decrement operator decreases integer value by one To add, use the Addition Operator − num1 + num2; In the same way, it works for Subtraction, Multiplication, ...

Read More

C# Program to create a Simple Thread

Samual Sam
Samual Sam
Updated on 19-Jun-2020 625 Views

To create a thread, I have created a function − public void myThread() {     for (int i = 0; i < 3; i++) {         Console.WriteLine("My Thread");     } } The above function is called to create a thread and a new ThreadStart delegate is created − Demo d = new Demo(); Thread thread = new Thread(new ThreadStart(d.myThread)); Example Create a simple thread using the following code. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; class Demo {     public void myThread() {         for (int i = 0; i &lt; 3; i++) {             Console.WriteLine(&quot;My Thread&quot;);         }     } } class NewThread { ...

Read More

C# program to Display Hostname and IP address

karthikeya Boyini
karthikeya Boyini
Updated on 19-Jun-2020 1K+ Views

To find the hostname, use the Dns.GetHostName() method in C# −String hostName = string.Empty; hostName = Dns.GetHostName(); Console.WriteLine("Hostname: "+hostName);Now, use the IPHostEntry.AddressList Property to get IP Address −IPHostEntry myIP = Dns.GetHostEntry(hostName); IPAddress[] address = myIP.AddressList;ExampleTry the following code to display hostname and IP address −using System; using System.Net; class Program {    static void Main() {       String hostName = string.Empty;       hostName = Dns.GetHostName();       Console.WriteLine("Hostname: "+hostName);       IPHostEntry myIP = Dns.GetHostEntry(hostName);       IPAddress[] address = myIP.AddressList;       for (int i = 0; i < address.Length; i++) {          Console.WriteLine("IP Address {1} : ",address[i].ToString());       }       Console.ReadLine();    } }

Read More
Showing 1621–1630 of 1,951 articles
« Prev 1 161 162 163 164 165 196 Next »
Advertisements