This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text.Json; | |
namespace ContosoCrafts.Website.Services; | |
public class JsonFileProductService | |
{ | |
public IWebHostEnvironment WebHostEnvironment { get; } | |
private string JsonFileName => | |
Path.Combine(WebHostEnvironment.WebRootPath, "data", "products.json"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string LargestNumber(int num1, int num2) => | |
num1 > num2 ? "number 1 is the greatest!" | |
: num2 > num1 ? "number 2 is the greatest!" | |
: "Both are equal!"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.FeatureManagement; | |
class Program | |
{ | |
static void Main() | |
{ | |
IFeatureManager featureManager = null; | |
if (featureManager.IsEnabledAsync(nameof(WidgetFeatureFlags.FeatureToggleABC)).Result) | |
{ | |
Console.WriteLine("Running task with new toggle"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Concurrent; | |
using System.Linq; | |
using System.Reflection; | |
public class MyEntity | |
{ | |
public string Name; | |
public string MacAddress; | |
public bool IsIncredible; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
var a = new A("test"); | |
var asJson = JsonConvert.SerializeObject( | |
a, | |
Formatting.None, | |
new JsonSerializerSettings | |
{ | |
NullValueHandling = NullValueHandling.Ignore | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Globalization; | |
var result = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.Local); | |
Console.WriteLine(result); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Item?> collection = new List<Item?>(); | |
foreach (var item in collection) | |
{ | |
if (item == null) | |
continue; | |
if (item.Field == "xyz") | |
{ | |
Console.WriteLine("Found it"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using NUnit.Framework; | |
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace EventTest2; | |
public static class Extensions | |
{ | |
private const int DEFAULT_HANDLE_POLLING_INTERVAL = 50; // ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net.Sockets; | |
string host = "192.168.1.45"; | |
int port = 5678; | |
byte[] getPowerCommand = { 0x81, 0x09, 0x04, 0x00, 0xff }; | |
// Create two clients - these will connect immediately | |
var client1 = new TcpClient(host, port); | |
client1.NoDelay = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
var foo = new Foo(); | |
Console.WriteLine(foo.ToString()); | |
public interface IFoo : IFormattable | |
{ | |
} | |
public class Foo : IFoo |