mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
[csharp/en] libary -> library
This commit is contained in:
parent
68e76a8c53
commit
8b06524f3d
@ -27,7 +27,7 @@ Multi-line comments look like this
|
|||||||
//public void MethodOrClassOrOtherWithParsableHelp() {}
|
//public void MethodOrClassOrOtherWithParsableHelp() {}
|
||||||
|
|
||||||
// Specify the namespaces this source code will be using
|
// Specify the namespaces this source code will be using
|
||||||
// The namespaces below are all part of the standard .NET Framework Class Libary
|
// The namespaces below are all part of the standard .NET Framework Class Library
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Dynamic;
|
using System.Dynamic;
|
||||||
@ -421,7 +421,7 @@ on a new line! ""Wow!"", the masses cried";
|
|||||||
// Item is an int
|
// Item is an int
|
||||||
Console.WriteLine(item.ToString());
|
Console.WriteLine(item.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// YIELD
|
// YIELD
|
||||||
// Usage of the "yield" keyword indicates that the method it appears in is an Iterator
|
// Usage of the "yield" keyword indicates that the method it appears in is an Iterator
|
||||||
// (this means you can use it in a foreach loop)
|
// (this means you can use it in a foreach loop)
|
||||||
@ -437,7 +437,7 @@ on a new line! ""Wow!"", the masses cried";
|
|||||||
foreach (var counter in YieldCounter())
|
foreach (var counter in YieldCounter())
|
||||||
Console.WriteLine(counter);
|
Console.WriteLine(counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// you can use more than one "yield return" in a method
|
// you can use more than one "yield return" in a method
|
||||||
public static IEnumerable<int> ManyYieldCounter()
|
public static IEnumerable<int> ManyYieldCounter()
|
||||||
{
|
{
|
||||||
@ -446,7 +446,7 @@ on a new line! ""Wow!"", the masses cried";
|
|||||||
yield return 2;
|
yield return 2;
|
||||||
yield return 3;
|
yield return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// you can also use "yield break" to stop the Iterator
|
// you can also use "yield break" to stop the Iterator
|
||||||
// this method would only return half of the values from 0 to limit.
|
// this method would only return half of the values from 0 to limit.
|
||||||
public static IEnumerable<int> YieldCounterWithBreak(int limit = 10)
|
public static IEnumerable<int> YieldCounterWithBreak(int limit = 10)
|
||||||
@ -482,7 +482,7 @@ on a new line! ""Wow!"", the masses cried";
|
|||||||
// ?? is syntactic sugar for specifying default value (coalesce)
|
// ?? is syntactic sugar for specifying default value (coalesce)
|
||||||
// in case variable is null
|
// in case variable is null
|
||||||
int notNullable = nullable ?? 0; // 0
|
int notNullable = nullable ?? 0; // 0
|
||||||
|
|
||||||
// ?. is an operator for null-propagation - a shorthand way of checking for null
|
// ?. is an operator for null-propagation - a shorthand way of checking for null
|
||||||
nullable?.Print(); // Use the Print() extension method if nullable isn't null
|
nullable?.Print(); // Use the Print() extension method if nullable isn't null
|
||||||
|
|
||||||
@ -913,17 +913,17 @@ on a new line! ""Wow!"", the masses cried";
|
|||||||
|
|
||||||
public DbSet<Bicycle> Bikes { get; set; }
|
public DbSet<Bicycle> Bikes { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Classes can be split across multiple .cs files
|
// Classes can be split across multiple .cs files
|
||||||
// A1.cs
|
// A1.cs
|
||||||
public partial class A
|
public partial class A
|
||||||
{
|
{
|
||||||
public static void A1()
|
public static void A1()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Method A1 in class A");
|
Console.WriteLine("Method A1 in class A");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A2.cs
|
// A2.cs
|
||||||
public partial class A
|
public partial class A
|
||||||
{
|
{
|
||||||
@ -932,9 +932,9 @@ on a new line! ""Wow!"", the masses cried";
|
|||||||
Console.WriteLine("Method A2 in class A");
|
Console.WriteLine("Method A2 in class A");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Program using the partial class "A"
|
// Program using the partial class "A"
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user