Found 2628 Articles for Csharp

Stack and Queue in C#

Ankith Reddy
Updated on 20-Jun-2020 15:02:54

4K+ Views

StackStack class represents a last-in, first out collection of object. It is used when you need a last-in, first-out access of items.The following is the property of Stack class −Count− Gets the number of elements in the stack.The following are the methods of Stack class −Sr.No.Method & Description1public virtual void Clear();Removes all elements from the Stack.2public virtual bool Contains(object obj);Determines whether an element is in the Stack.3public virtual object Peek();Returns the object at the top of the Stack without removing it.4public virtual object Pop();Removes and returns the object at the top of the Stack.5public virtual void Push(object obj);Inserts an object ... Read More

Ternary Operator in C#

karthikeya Boyini
Updated on 20-Jun-2020 14:43:03

3K+ Views

Ternary operator is a Conditional operator in C#. It takes three arguments and evaluates a Boolean expression.For example −b = (a == 1) ? 20 : 30;Above, if the first operand evaluates to true (1), the second operand is evaluated. If the first operand evaluates to false (0), the third operand is evaluated.The following is an example −Example Live Demousing System; namespace DEMO {    class Program {       static void Main(string[] args) {          int a, b;          a = 10;          b = (a == 1) ? 20 : 30;          Console.WriteLine("Value of b is {0}", b);          b = (a == 10) ? 20 : 30;          Console.WriteLine("Value of b is {0}", b);          Console.ReadLine();       }    } }OutputValue of b is 30 Value of b is 20

static keyword in C#

George John
Updated on 20-Jun-2020 14:44:40

3K+ Views

We can define class members as static using the static keyword. When we declare a member of a class as static, it means no matter how many objects of the class are created, there is only one copy of the static member.The keyword static implies that only one instance of the member exists for a class. Static variables are used for defining constants because their values can be retrieved by invoking the class without creating an instance of it.The following is an example showing the usage of static variables −Example Live Demousing System; namespace StaticVarApplication {    class StaticVar { ... Read More

Threads in C#

Samual Sam
Updated on 20-Jun-2020 14:43:40

529 Views

A thread is defined as the execution path of a program. Each thread defines a unique flow of control. If your application involves complicated and time-consuming operations, then it is often helpful to set different execution paths or threads, with each thread performing a particular job.The life cycle of a thread starts when an object of the System.Threading.Thread class is created and ends when the thread is terminated or completes execution.The following are the various states in the life cycle of a thread −The Unstarted State - It is the situation when the instance of the thread is created but ... Read More

What are pointer data types in C#?

karthikeya Boyini
Updated on 20-Jun-2020 14:45:09

1K+ Views

A pointer is a variable whose value is the address of another variable i.e., the direct address of the memory location. Similar to any variable or constant, you must declare a pointer before you can use it to store any variable address.The syntax of a pointer is −type *var-name;The following is how you can declare a pointer type −int *ip; /* pointer to an integer */ double *dp; /* pointer to a double */C# allows using pointer variables in a function of code block when it is marked by the unsafe modifier. The unsafe code or the unmanaged code is ... Read More

Static binding vs Dynamic binding in C#

Arjun Thakur
Updated on 20-Jun-2020 14:49:26

2K+ Views

Polymorphism can be static or dynamic. In static polymorphism, the response to a function is determined at the compile time. In dynamic polymorphism, it is decided at run-time.Compile Time Polymorphism or Static BindingThe mechanism of linking a function with an object during compile time is called early binding. It is also called static binding or early binding.Run Time Polymorphism or Dynamic BindingRuntime polymorphism has method overriding that is also known as dynamic binding or late binding.Abstract classes contain abstract methods, which are implemented by the derived class. The derived classes have more specialized functionality. Dynamic polymorphism is implemented by abstract classes and virtual functions.Read More

Static class in C#

Samual Sam
Updated on 20-Jun-2020 14:49:07

606 Views

The C# static class cannot be instantiated and can only have only static members. The static class in C# is sealed and cannot contain instance constructors.The following is an example with static class and static members −Example Live Demousing System; public static class Demo {    public static float PI = 3.14f;    public static int calc(int n){return n*n;} } class Program {    public static void Main(string[] args) {       Console.WriteLine("PI: "+Demo.PI);       Console.WriteLine("Square: " + Demo.calc(3));    } }OutputPI: 3.14 Square: 9Above, the static class is −public static class Demo {   ... Read More

Major features of C# programming

karthikeya Boyini
Updated on 20-Jun-2020 14:49:42

2K+ Views

C# is a modern, general-purpose, object-oriented programming language developed by Microsoft. C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that allows the use of various high-level languages on different computer platforms and architectures.The following are the major features of C# −Following is the list of few important features of C# −Boolean ConditionsAutomatic Garbage CollectionStandard LibraryAssembly VersioningProperties and EventsDelegates and Events ManagementEasy-to-use GenericsIndexersConditional CompilationSimple MultithreadingLINQ and Lambda ExpressionsIntegration with Windows

IS vs AS Operators in C#

Chandu yadav
Updated on 20-Jun-2020 14:51:34

856 Views

IS operatorThe "is" operator in C# checks whether the run-time type of an object is compatible with a given type or not.The following is the syntax −expr is typeHere, expr is the expressiontype is the name of the typeThe following is an example showing the usage of is operator in C# &minis;Example Live Demousing System; class One { } class Two { } public class Demo {    public static void Test(object obj) {       One x;       Two y;       if (obj is One) {          Console.WriteLine("Class One"); ... Read More

Write a C# function to print nth number in Fibonacci series?

Samual Sam
Updated on 20-Jun-2020 14:25:20

509 Views

Set the following, if the nth number is let’s say num −int n = num- 1; int[] val = new int[n + 1];Then set the default Fibonacci numbers on the first and second position −val[0]= 0; val[1]= 1;Loop through i=2 to i

Advertisements