Někdy se vám může stát, že chcete do metody předat předem neznámý počet parametrů. Vyřešit to můžete lehce předáním kolekce apod. Nicméně je zde ještě jedna možnost. Jedná se o klíčové slovo params. Tímto klíčovým slovem umožníte předat do metody parametry prostým zadáním a uvnitř je zpracovat jako kolekci. Výsledek pak vypadá takto:
static void Main(string[] args)
{
Foo(10, 20, 30);
}
static void Foo(params int[] numbers)
{
foreach (int i in numbers)
{
Console.WriteLine(i);
}
}
Jednoduché a rychlé.
Před několika měsíci jsem popisoval
Sortování v generické kolekci anonymní metodou. Doba pokročila (C#3.0 a .NET 3.5) a tak není třeba vytvářet delegáta, můžete využít lambda expression (výsledek je ale stejný) a ušetřit si trochu psaní – možná i trochu zlepšit čitelnost kódu.
public void SortByPosition(bool descending)
{
((List<int>)this.Items).Sort((item1, item2) => (descending ? -1 : 1) * item1.CompareTo(item2));
}
Did you know, that you can use in Firebird .NET Data Provider more “firebirdish” connection strings?
You can put into FbConnection "database=<hostname/port:path>;user=<user>;password=<password> or the hostname/port:path can be //hostname:port/path.
If you’re looking to some articles/resources/documents you may find, that “greater than or equal” or “lower than or equal” operators have keywords gteq or lteq. But when you try these, the request fails.
Well, the simple reason is, that these operators are in fact ge or le. Hope this helps you save some time when trying to find out what’s wrong.
Today, after some days/weeks, I finally created some noticable (= not only internals) progress with Entity Framework provider for Firebird.
Now, the provider is able to use, map, call, … stored procedures (and functions [very experimental]). You can select stored procedures from database, map these to some operations in EF, create “function imports” etc. You can see this working on picture:
I have not tested all available options of calling etc. SPs, so feel free to report any problems with it. Current version can be downloaded from netprovider.cincura.net (aka weekly builds).
Also take into account, that current latest stable (old ones too) version of FB has left outer join bug, so all columns in table are marked as primary key(s) (and so must be not null). I’m wondering how this (from my POV) really serious bug can go thru QA tests?!
Known Issue: When you select “Update Model from Database” in Visual Studio you get error. I’m now working on it.
Anyway for testing, I recommend you to use EdmGen (or EdmGen2), it’s faster and more controlled.
The EdmGen tool available in Entity Framework or simply SP1 installation is good tool for playing with CSDL, SSDL and MSL files. On the other hand, when using Visual Studio you get all these files in one EDMX file. Though it’s just a pack of these two files, you cannot use it as input/output for EdmGen.
Fortunately there’s a solution – EdmGen2. It’s simply EdmGen on steroids.
EdmGen2 can read and write EDMX files and also translate between EDMX and CSDL, SSDL and MSL files. The source code is also available, so you can use sources as learning material to API in System.Data.Entity.Design.