Found 2628 Articles for Csharp

What is Lambda expression in C#?

Nizamuddin Siddiqui
Updated on 05-Nov-2020 13:50:58

414 Views

Lambda expression is a better way to represent an anonymous method. Both anonymous methods and Lambda expressions allow you define the method implementation inline, however, an anonymous method explicitly requires you to define the parameter types and the return type for a method.Expression lambda that has an expression as its body: (input−parameters) => expressionStatement lambda that has a statement block as its body: (input−parameters) => { }Any lambda expression can be converted to a delegate type. The delegate type to which a lambda expression can be converted is defined by the types of its parameters and return value. If ... Read More

How to check in C# whether the string array contains a particular work in a string array?

Nizamuddin Siddiqui
Updated on 04-Oct-2023 21:43:08

27K+ Views

In C#, String.Contains() is a string method. This method is used to check whether the substring occurs within a given string or not. It returns the boolean value. If substring exists in string or value is the empty string (""), then it returns True, otherwise returns False. Exception − This method can give ArgumentNullException if str is null. This method performs the case-sensitive checking. The search will always begin from the first character position of the string and continues until the last character position. Example 1 Contains is case sensitive if the string is found it return true else false ... Read More

How to use “not in” query with C# LINQ?

Nizamuddin Siddiqui
Updated on 05-Nov-2020 13:48:09

5K+ Views

Except operator are designed to allow you to query data which supports the IEnumerable

What is the difference between the | and || or operators in C#?

Nizamuddin Siddiqui
Updated on 05-Nov-2020 13:46:18

2K+ Views

| OperatorThe | operator computes the logical OR of its operands. The result of x | y is true if either x or y evaluates to true. Otherwise, the result is false.The | operator evaluates both operands even if the left-hand operand evaluates to true, so that the operation result is true regardless of the value of the right-hand operand.|| OperatorThe conditional logical OR operator ||, also known as the "short−circuiting" logical OR operator, computes the logical OR of its operands.The result of x || y is true if either x or y evaluates to true. Otherwise, the result is ... Read More

How to get the ip address in C#?

Nizamuddin Siddiqui
Updated on 05-Nov-2020 13:44:33

946 Views

IP (Internet Protocol) Address is an address of your network hardware. It helps in connecting your computer to other devices on your network and all over the world. An IP Address is made up of numbers or characters.All devices that are connected to an internet connection have a unique IP address which means there’s a need of billions of IP addresses. This requirement is fulfilled by the new IP version IPv6.Private IP AddressA private IP address is the address of your device connected on the home or business network. If you have a few different devices connected to one ISP ... Read More

How to Deserializing JSON to .NET object using Newtonsoft json in C# and pick only one value from the array?

Nizamuddin Siddiqui
Updated on 05-Nov-2020 13:42:44

480 Views

The WebClient class provides common methods for sending data to or receiving data from any local, intranet, or Internet resource identified by a URI.The WebClient class uses the WebRequest class to provide access to resources. WebClient instances can access data with any WebRequest descendant registered with the WebRequest.RegisterPrefix method.DownloadString Downloads a String from a resource and returns a String.If your request requires an optional header, you must add the header to the Headers collectionExampleIn the below example we are calling the url "https://jsonplaceholder.typicode.com/posts"The example is then deserialized to User arrayFrom the user array we are printing the first array valueExampleclass ... Read More

How do I overload the [] operator in C#?

Nizamuddin Siddiqui
Updated on 05-Nov-2020 13:40:59

233 Views

The [] operator is called an indexer.An indexer allows an object to be indexed such as an array. When you define an indexer for a class, this class behaves similar to a virtual array. You can then access the instance of this class using the array access operator ([ ]).Indexers can be overloaded. Indexers can also be declared with multiple parameters and each parameter may be a different type. It is not necessary that the indexes have to be integers.Example 1static void Main(string[] args){    IndexerClass Team = new IndexerClass();    Team[0] = "A";    Team[1] = "B";    Team[2] ... Read More

How to check whether you are connected to Internet or not in C#?

Nizamuddin Siddiqui
Updated on 05-Nov-2020 13:37:58

926 Views

There are many ways to check whether internet is connected to a machine in C# or not. Make use of System.Net namespace which provides common methods for sending data to and receiving data from a resource identified by a URI. The WebClient or HttpClient class provides common methods for sending data to or receiving data from any local, intranet, or Internet resource identified by a URI. Here in the below example we have used (OpenRead)Returns the data from a resource as a Stream.Checks by hitting the url "http://google.com/generate_204" if success return true else false.The below example runs in the loop ... Read More

How do you get the file size in C#?

Nizamuddin Siddiqui
Updated on 25-Sep-2020 11:19:43

2K+ Views

The FileInfo class is used to deal with file and its operations in C#.It provides properties and methods that are used to create, delete and read file. It uses StreamWriter class to write data to the file. It is a part of System.IO namespace.The Directory property retrieves an object that represents the parent directory of a file.The DirectoryName property retrieves the full path of the parent directory of a file.The Exists property checks for the presence of a file before operating on it.The IsReadOnly property retrieves or sets a value that specifies whether a file can be modified.The Length retrieves ... Read More

How to write Regex for numbers only in C#?

Nizamuddin Siddiqui
Updated on 25-Sep-2020 11:17:58

2K+ Views

A regular expression is a pattern that could be matched against an input text.The .Net framework provides a regular expression engine that allows such matching.A pattern consists of one or more character literals, operators, or constructs.Here are basic pattern metacharacters used by RegEx −* = zero or more ? = zero or one ^ = not [] = rangeThe ^ symbol is used to specify not condition.the [] brackets if we are to give range values such as 0 - 9 or a-z or A-ZExampleclass Program{    public static void Main(){       string num = "123dh";     ... Read More

Advertisements