public static void Main() { }
public static int Main() { }
public static void Main(string[] args) { }
public static int Main(string[] args) { }
public static async Task Main() { }
public static async Task<int> Main() { }
public static async Task Main(string[] args) { }
public static async Task<int> Main(string[] args) { }
if($(window).width() < 992){
//function
}
$(window).resize(function(){
if($(window).width() < 992){
//function
}
})
if(window.innerWidth < 992){
//do function
}
window.addEventListener("resize", function(){
if(window.innerWidth < 992){
//do function
}
}, false);
bool _isCalculated;
public bool IsCalc
get
{
return _isCalculated;
}
set{
if (value != _isCalculated)
{
_isCalculated = value;
SaveMeInDbMethod(_isCaluclated);
// TODO: посмотреть в гугл NotifyPropertyChanged или RaisePropertyChanged() в VievModel
NotifyPropertyChanged("IsCalc");
}
namespace TryEnum
{
enum DownloadType
{
Video, Audio, Custom, Unknown, Default
}
enum ForceIpProtocol
{
IPv4, IPv6
}
enum ProxyProtocol
{
HTTPS, HTTP, SOCKS4, SOCKS5
}
}
class ClassName : IClassName
, но это не совсем наследование, там немножко другая реализация). И интерфейс нужен в том случае, если нужно реализовать полиморфизм в коде и/или что бы упростить доступ к публичным полям в классах, которые реализуют этот интерфейс. static void Create()
{
// empty...
}
class SimpleHuman : IHuman
{
public string Name { get; set; }
public int Age { get; set; }
public SimpleHuman()
{
Name = "Generic human...";
Age = 20;
}
public SimpleHuman(string name) : this()
{
Name = name;
}
public SimpleHuman(string name, int age) : this()
{
Name = name;
Age = age;
}
}
class CoolHuman : IHuman
{
public string Name { get; set; }
public int Age { get; set; }
public CoolHuman()
{
Name = "BOB!";
Age = 20;
}
public CoolHuman(string name) : this()
{
Name = name;
}
public CoolHuman(string name, int age) : this()
{
Name = name;
Age = age;
}
}
interface IHuman
{
string Name { get; set; }
int Age { get; set; }
}
class Create
{
public IHuman Human { get; set; }
public Create()
{
Human = new CoolHuman();
}
public void Hello()
{
Console.WriteLine("Hello, {0}. Today you are {1} years old", Human.Name, Human.Age);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace TestTrapCtrlC{
public class Program{
static bool exitSystem = false;
#region Trap application termination
[DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler(EventHandler handler, bool add);
private delegate bool EventHandler(CtrlType sig);
static EventHandler _handler;
enum CtrlType {
CTRL_C_EVENT = 0,
CTRL_BREAK_EVENT = 1,
CTRL_CLOSE_EVENT = 2,
CTRL_LOGOFF_EVENT = 5,
CTRL_SHUTDOWN_EVENT = 6
}
private static bool Handler(CtrlType sig) {
Console.WriteLine("Exiting system due to external CTRL-C, or process kill, or shutdown");
//do your cleanup here
Thread.Sleep(5000); //simulate some cleanup delay
Console.WriteLine("Cleanup complete");
//allow main to run off
exitSystem = true;
//shutdown right away so there are no lingering threads
Environment.Exit(-1);
return true;
}
#endregion
static void Main(string[] args) {
// Some biolerplate to react to close window event, CTRL-C, kill, etc
_handler += new EventHandler(Handler);
SetConsoleCtrlHandler(_handler, true);
//start your multi threaded program here
Program p = new Program();
p.Start();
//hold the console so it doesn’t run off the end
while(!exitSystem) {
Thread.Sleep(500);
}
}
public void Start() {
// start a thread and start doing some processing
Console.WriteLine("Thread started, processing..");
}
}
}
попытался решить все через рекурсию
const createTree = (data, idKey, parentKey, parentId) =>
data.reduce((acc, n) => (parentId === n[parentKey] && acc.push({
...n,
children: createTree(data, idKey, parentKey, n[idKey]),
}), acc), []);
const tree = createTree(data, 'id', 'parentId', null);
function createTree(data, idKey, parentKey) {
const tree = Object.fromEntries(data.map(n => [ n[idKey], { ...n, children: [] } ]));
return Object
.values(tree)
.filter(n => !(tree[n[parentKey]] && tree[n[parentKey]].children.push(n)));
}
const tree = createTree(data, 'id', 'parentId');
function createTreeData(arr, idKey, parentKey) {
const tree = Object.fromEntries(arr.map(n => [ n[idKey], { ...n, children: [] } ]));
return Object.values(tree).filter(n => !tree[n[parentKey]]?.children.push(n));
}
const treeData = createTreeData(data, 'id', 'parent_id');
const createTreeHTML = data =>
Array.isArray(data) && data.length
? `<ul>${data.map(n => `
<li>
${n.name}
${createTreeHTML(n.children)}
</li>`).join('')}
</ul>`
: '';
document.body.insertAdjacentHTML('beforeend', createTreeHTML(treeData));
const createTreeElement = data =>
data instanceof Array && data.length
? data.reduce((ul, n) => (
ul.append(document.createElement('li')),
ul.lastChild.append(n.name, createTreeElement(n.children)),
ul
), document.createElement('ul'))
: '';
document.body.append(createTreeElement(treeData));
function createTreeElement(arr, idKey, parentKey) {
const tree = arr.reduce((acc, { [parentKey]: n }) => (
acc[n] = acc[n] ?? document.createElement('ul'),
acc
), {});
arr.forEach(n => (
tree[n[parentKey]].append(document.createElement('li')),
tree[n[parentKey]].lastChild.append(n.name, tree[n[idKey]] ?? '')
));
return Object.values(tree).reduce((ul, n) => (
n.parentNode || ul.append(...n.children),
ul
), document.createElement('ul'));
// или, если не надо объединять в общий список элементы, у которых разные корневые parent_id
// return Object.values(tree).filter(n => !n.parentNode);
}
document.body.append(createTreeElement(data, 'id', 'parent_id'));