Found 2587 Articles for Csharp

How do interfaces work in C#?

Akshay Khot
Updated on 19-May-2021 07:47:44

561 Views

An interface defines a contract that will be implemented by a class or a struct. It can contain methods, properties, events, and indexers. An interface is similar to a class except that it doesn't hold any data and only specifies the behavior it can do (or more accurately, the class that implements it can do).A class can implement one or more interfaces. To implement an interface member, the class should have a public member with the same method definition as the interface member, i.e. same name and signature.For example, IComparer is an interface defined in the System.Collections namespace that defines ... Read More

What is the usage of ref, out, and in keywords in C#?

Akshay Khot
Updated on 19-May-2021 07:41:00

550 Views

In C#, most of the methods can have zero or more parameters which define the data that must be provided to the method. Any code that calls the method has to pass the data (called arguments) to the method. A method declares its inputs as parameters, and they're provided by calling code in the form of arguments.For example, consider the following method and subsequent method call.static void Greet(string greeting){    Console.WriteLine(greeting); } ... Greet("Hello");In the above example, greeting is a parameter of the Greet() method, and "Hello" is an argument passed to the method.When you call a method and pass ... Read More

Provide a brief overview of the C# and .NET ecosystem

Akshay Khot
Updated on 19-May-2021 07:40:00

676 Views

C# is an object-oriented, type-safe and general-purpose programming language, which focuses on making the programmers productive. It tries to achieve this productivity through expressiveness, simplicity and a focus on performance. It works on different platforms such as Windows, Mac, and Linux.Type-SafetyC# is a statically typed language. That means the types are verified when you compile a program. This eliminates a large set of errors before the program even runs.Garbage CollectionAutomatic memory management is an essential feature of C#. It has a garbage collector that runs along with the programs, reclaiming the unused memory. This frees the burden from programmers to ... Read More

Explain and contrast value types and reference types in C#

Akshay Khot
Updated on 19-May-2021 07:33:11

328 Views

In general, all types in C# can be divided into two main categories − value types and reference types. Let's look at each type in detail.Value TypesVariables of value types directly contain their data. Each variable has its own copy of the data. Hence it is impossible for a variable of value type to modify another object.A value type can be one of the following types −all numeric types, e.g., int, float, and doublechar and the bool typesstruct type orenumeration type.A value type simple contains the value. For example, the integer type contains the actual number, and not a pointer ... Read More

C# and Selenium: Wait Until Element is Present

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:45:02

7K+ Views

We can wait until an element is present in Selenium webdriver using the explicit wait. It is mainly used whenever there is a synchronization issue for an element to be available on page.The WebDriverWait and the ExpectedCondition classes are used for an explicit wait implementation. We have to create an object of the WebDriverWait which shall invoke the methods of the ExpectedCondition class.The webdriver waits for a specified amount of time for the expected criteria to be met. After the time has elapsed, an exception gets thrown. To wait for an element to be present, we have to use the ... Read More

Moving mouse pointer to a specific location or element using C# and Selenium

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:38:51

7K+ Views

We can move mouse pointer to a specific location or element in Selenium webdriver(C#) using the Actions class. We have to first create an object of this class.Next to move an element we have to apply the MoveToElement method and pass the element locator as a parameter to this method. Finally, to actually perform this task the method Perform is to be used.After moving to an element, we can click on it with the Click method. To move to a specific location, we have to use the MoveByOffset method and then pass the offset numbers to be shifted along the ... Read More

How to open a browser window in full screen using Selenium WebDriver with C#?

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:13:21

2K+ Views

We can open a browser window in full screen using Selenium webdriver in C# by using the method Maximize. This method has to be applied on the webdriver object.Syntaxdriver.Manage().Window.Maximize();Exampleusing NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using System; namespace NUnitTestProject1{    public class Tests{       String url = "https://www.google.com/";       IWebDriver driver;       [SetUp]       public void Setup(){          //object of FirefoxDriver          driver = new FirefoxDriver();       }       [Test]       public void Test1(){          //URL launch          driver.Navigate().GoToUrl(url);          //browser maximize          driver.Manage().Window.Maximize();          Console.WriteLine("Browser Maximized");       }       [TearDown]       public void closeBrowser(){          driver.Quit();       }    } }Output

Difference Between Interface and Abstract Class in Java & C#

AmitDiwan
Updated on 24-Mar-2021 13:13:43

701 Views

In this post, we will understand the difference between abstract class and interface in Java and C#.Abstract ClassIt contains the declaration and definition part.Multiple inheritance can’t be implemented using abstract class.It contains the constructor.It can also contain some static members.It can contain multiple types of access modifiers such as public, private, protected.The performance of an abstract class is very good, because it is quick.It is used to implement the core identity/functionality of a class.A class can use only one abstract class.If many implementations are same, and they have a common behaviour, it is suggested to use an abstract class.Abstract classes ... Read More

Difference Between ref and out in C#

AmitDiwan
Updated on 24-Mar-2021 13:09:58

901 Views

In this post, we will understand the difference between ‘ref’ and ‘out’ in C#.Ref keywordBefore passing the parameters to ‘ref’, they need to be initialized.It is not necessary to initialize the value of the parameter before it returns to the calling method.The data can pass in two directions when the ‘ref’ keyword is used.It is useful when the called method needs to change the value of the parameter that is passed.Out keywordIt is not required to initialize parameters before it is passed to ‘out’.It is required to initialize the value of a parameter before it is returned to the calling ... Read More

Difference Between Delegates and Events in C#

AmitDiwan
Updated on 24-Mar-2021 13:06:37

2K+ Views

In this post, we will understand the difference between delegates and events in C#.DelegateIt can be declared using the ‘delegate’ keyword.It is a function pointer.It holds the reference to one or more methods during runtime.It is an independent keyword.It doesn’t depend on events.It contains the Combine() and Remove() methods that help add methods to the list of invocation.It can be passed as a parameter to a method.The ‘=’ operator can be used to assign a single method.The ‘+=’ operator can be used to assign multiple methods to a delegate.EventIt can be declared using the ‘event’ keyword.It can be defined as ... Read More

Advertisements