Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ public CList(IEnumerable<T> collection) : base(collection)
public CList() : base()
{}

public override String ToString()
public override string ToString()
{
String retVal = String.Empty;
string retVal = string.Empty;
foreach (T item in this) {
if (String.IsNullOrEmpty(retVal))
if (string.IsNullOrEmpty(retVal))
retVal += item.ToString();
else
retVal += String.Format(", {0}", item);
retVal += string.Format(", {0}", item);
}
return retVal;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@

public static class StringExtensions
{
public static String ToString2<T>(this List<T> l)
public static string ToString2<T>(this List<T> l)
{
String retVal = String.Empty;
string retVal = string.Empty;
foreach (T item in l)
retVal += String.Format("{0}{1}", String.IsNullOrEmpty(retVal) ?
retVal += string.Format("{0}{1}", string.IsNullOrEmpty(retVal) ?
"" : ", ",
item);
return String.IsNullOrEmpty(retVal) ? "{}" : "{ " + retVal + " }";
return string.IsNullOrEmpty(retVal) ? "{}" : "{ " + retVal + " }";
}

public static String ToString<T>(this List<T> l, String fmt)
public static string ToString<T>(this List<T> l, string fmt)
{
String retVal = String.Empty;
string retVal = string.Empty;
foreach (T item in l) {
IFormattable ifmt = item as IFormattable;
if (ifmt != null)
retVal += String.Format("{0}{1}",
String.IsNullOrEmpty(retVal) ?
retVal += string.Format("{0}{1}",
string.IsNullOrEmpty(retVal) ?
"" : ", ", ifmt.ToString(fmt, null));
else
retVal += ToString2(l);
}
return String.IsNullOrEmpty(retVal) ? "{}" : "{ " + retVal + " }";
return string.IsNullOrEmpty(retVal) ? "{}" : "{ " + retVal + " }";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
public class Automobile
{
private int _doors;
private String _cylinders;
private string _cylinders;
private int _year;
private String _model;
private string _model;

public Automobile(String model, int year , int doors,
String cylinders)
public Automobile(string model, int year , int doors,
string cylinders)
{
_model = model;
_year = year;
Expand All @@ -20,40 +20,40 @@ public Automobile(String model, int year , int doors,
public int Doors
{ get { return _doors; } }

public String Model
public string Model
{ get { return _model; } }

public int Year
{ get { return _year; } }

public String Cylinders
public string Cylinders
{ get { return _cylinders; } }

public override String ToString()
public override string ToString()
{
return ToString("G");
}

public String ToString(String fmt)
public string ToString(string fmt)
{
if (String.IsNullOrEmpty(fmt))
if (string.IsNullOrEmpty(fmt))
fmt = "G";

switch (fmt.ToUpperInvariant())
{
case "G":
return String.Format("{0} {1}", _year, _model);
return string.Format("{0} {1}", _year, _model);
case "D":
return String.Format("{0} {1}, {2} dr.",
return string.Format("{0} {1}, {2} dr.",
_year, _model, _doors);
case "C":
return String.Format("{0} {1}, {2}",
return string.Format("{0} {1}, {2}",
_year, _model, _cylinders);
case "A":
return String.Format("{0} {1}, {2} dr. {3}",
return string.Format("{0} {1}, {2} dr. {3}",
_year, _model, _doors, _cylinders);
default:
String msg = String.Format("'{0}' is an invalid format string",
string msg = string.Format("'{0}' is an invalid format string",
fmt);
throw new ArgumentException(msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class Example
{
public static void Main()
{
String[] cultureNames = { "en-US", "en-GB", "fr-FR",
string[] cultureNames = { "en-US", "en-GB", "fr-FR",
"hr-HR", "ja-JP" };
Decimal value = 1603.49m;
foreach (var cultureName in cultureNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ private async Task<string> DelayAsync()
// Exception Message: canceled
// Task IsCanceled: True
// Task IsFaulted: False

//</Snippet2>


Expand Down Expand Up @@ -116,4 +115,4 @@ private async Task ExcAsync(string info)
//</Snippet4>
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ in BaseClass(int i)
*/
//</snippet2>

namespace Example1 //for redefinition of Employee
{
//<snippet4>
public class Employee
{
private string alias;
private string name;

public Employee(string name, string alias)
{
// Use this to qualify the members of the class
// instead of the constructor parameters.
this.name = name;
this.alias = alias;
}
}
//</snippet4>
}

namespace Example2 //for redefinition of Employee
{
//<snippet3>
Expand All @@ -102,14 +121,13 @@ class Employee
private decimal salary = 3000.00m;

// Constructor:
//<snippet4>
public Employee(string name, string alias)
{
// Use this to qualify the fields, name and alias:
this.name = name;
this.alias = alias;
}
//</snippet4>

// Printing method:
public void printEmployee()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,34 @@ void ReadFile(int index)

//<snippet2>
class TryFinallyTest
{
static void ProcessString(string s)
{
if (s == null)
static void ProcessString(string s)
{
throw new ArgumentNullException();
if (s == null)
{
throw new ArgumentNullException();
}
}
}

static void Main()
{
string s = null; // For demonstration purposes.

try
{
ProcessString(s);
}

catch (Exception e)
static void Main()
{
Console.WriteLine("{0} Exception caught.", e);
string s = null; // For demonstration purposes.

try
{
ProcessString(s);
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
}
}
}
/*
Output:
System.ArgumentNullException: Value cannot be null.
at TryFinallyTest.Main() Exception caught.
* */

//</snippet2>

//<snippet3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private static void ProvidesFormatInfo(object obj)
Console.Write("A null object reference: ");
Console.WriteLine("Its use could result in a NullReferenceException");
}
else if (obj is var _)
else
Console.WriteLine($"Some object type without format information");
}
}
Expand Down
1 change: 1 addition & 0 deletions windowsforms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ If you're new to .NET Core, here are a few resources to help you understand the
| Sample Name | Description |
| ----------- | ----------- |
| [Hello World - shared source](helloworld-sharedsource) | This sample shows you how to share source between a .NET Framework WinForms application and a .NET Core WinForms application. Use this to get the full .NET Framework tooling experience while still building for .NET Core. |
| [Matching Game](matching-game) | This sample demonstrates simple event handling and timers in a .NET Core 3 WinForms application |

## Getting Started

Expand Down
Loading