مثال 1: نوع <IEnumerator<T با حلقهی foreach سازگار نیست
public interface IEnumerator<out T> : IEnumerator, IDisposable { // // Summary: // Gets the element in the collection at the current position of the enumerator. // // Returns: // The element in the collection at the current position of the enumerator. T Current { get; } }
Error CS1579 foreach statement cannot operate on variables of type ‘IEnumerator’ because ‘IEnumerator’ does not contain a public instance or extension definition for ‘GetEnumerator’
static class Extensions { public static IEnumerator<T> GetEnumerator<T>(this IEnumerator<T> enumerator) => enumerator; }
اکنون حلقهی foreach را میتوان بر روی نوعهای <IEnumerator<T نیز بکار گرفت:
class Program { void Main() { var enumerator = Enumerable.Range(0, 10).GetEnumerator(); foreach (var item in enumerator) { Console.WriteLine(item); } } }
این نکته بر روی نمونهی async آن نیز قابل اعمال است که مثالی از آنرا در ادامه مشاهده میکنید:
static class Extensions { public static IAsyncEnumerator<T> GetAsyncEnumerator<T>(this IAsyncEnumerator<T> enumerator) => enumerator; } class Program { static async Task Main() { var enumerator = GetAsyncEnumerator(); await foreach (var item in enumerator) { Console.WriteLine(item); } } static async IAsyncEnumerator<int> GetAsyncEnumerator() { yield return 0; await Task.Delay(1); yield return 1; } }
مثال زیر را درنظر بگیرید:
class Program { static void Main() { foreach (var item in (1, 2, 3)) { Console.WriteLine(item); } } }
foreach statement cannot operate on variables of type '(int, int, int)' because '(int, int, int)' does not contain a public instance or extension definition for 'GetEnumerator' [CS9Features]csharp(CS1579)
static class Extensions { public static IEnumerator<object> GetEnumerator<T1, T2, T3>(this ValueTuple<T1, T2, T3> tuple) { yield return tuple.Item1; yield return tuple.Item2; } }
پشتیبانی از JSON در sql server 2016
At last, SQL Server has caught up with other RDBMSs by providing a useful measure of JSON-support. It is a useful start, even though it is nothing like as comprehensive as the existing XML support. For many applications, what is provided will be sufficient. Robert Sheldon describes what is there and what isn't.
سیلورلایت 5 و تاریخ شمسی
.NotSupportedException: The method 'Max' is not supported
This topic provides information about the way in which LINQ queries are composed and executed when you are using the WCF Data Services client and limitations of using LINQ to query a data service that implements the Open Data Protocol (OData). For more information about composing and executing queries against an OData-based data service, see Querying the Data Service (WCF Data Services). Composing LINQ Queries LINQ enables you to compose queries against a collection of objects that implements IEnumerable. Both the Add Service Reference dialog box in Visual Studio and the DataSvcUtil.exe tool are used to generate a representation of an OData service as an entity container class that inherits from DataServiceContext, as well as objects that represent the entities returned in feeds. These tools also generate properties on the entity container class for the collections that are exposed as feeds by the service. Each of these properties of the class that encapsulates the data service return a DataServiceQuery. Because the DataServiceQuery class implements the IQueryable interface defined by LINQ, the WCF Data Services you can compose a LINQ query against feeds exposed by the data service, which are translated by the client library into a query request URI that is sent to the data service on execution. Note: The set of queries expressible in the LINQ syntax is broader than those enabled in the URI syntax that is used by OData data services. A NotSupportedException is raised when the query cannot be mapped to a URI in the target data service. For more information, see the Unsupported LINQ Methods in this topic.
نگاهی به Fluent Interfaces
تاثیرات حضور دیگران در برنامه نویسی
The "Blazor United" effort is really a collection of features we're adding to Blazor so that you can get the best of server & client based web development. These features include: Server-side rendering, streaming rendering, enhanced navigations & form handling, add client interactivity per page or component, and determining the client render mode at runtime. We've started delivering server-side rendering support for Blazor with .NET 8 Preview 3, which is now available to try out. We plan to deliver the remaining features in upcoming previews. We hope to deliver them all for .NET 8, but we'll see how far we get.