c#-4.0

Forcing named arguments in C#

青春壹個敷衍的年華 提交于 2020-03-17 06:31:29
问题 C# 4 introduced a feature called named arguments which is especially useful in scenarios like int RegisterUser(string nameFirst, string nameLast, string nameMiddle, string email) Is there a way to force using named arguments? Maybe some attribute to apply to a method or a compiler switch I'm not aware of? I guess it can be done with code inspector tools but just want to know if there is other way. p.s. For those interested why one may need it and why not just use a class/struct to utilize

Unity 5.5.2f1 to 5.6.1f1 - interpolated strings error?

橙三吉。 提交于 2020-03-14 10:19:10
问题 I've just updated my Unity version from 5.5.2f1 to 5.6.1f1. Suddenly I get the error: Feature `interpolated strings' cannot be used because it is not part of the C# 4.0 language specification The code below worked well before updating. public class SensorData { public int Timestamp { get; set; } public float Humidity { get; set; } public float Temp { get; set; } public int Light { get; set; } public int Button { get; set; } public override string ToString() { return $"{Timestamp}, {Humidity},

How to convert string to bool and evaluate the condition? [closed]

僤鯓⒐⒋嵵緔 提交于 2020-03-05 00:23:50
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 14 days ago . I have to convert a string to bool and evaluate the string condition. For example: string condition = "8 > 9 || !8"; then the condition has to evaluate and return true; if string condition = "!8"; then condition has to return true. Suggest me how to evaluate the condition. 回答1:

user-defined scalar function to generate computed column

雨燕双飞 提交于 2020-03-04 21:33:53
问题 I have databse having 2 tables i.e (Installment and InstallmentPlan). In the installment table there are number of columns. I want to add one new computed column name SurchargeCalculated (SC). The calculation for SC is this SC = (Installment.Amount * Installment.days * (InstallmentPlan.InstPercentage /365 /100)) I have created user-defined function SurchargeCal having 3 parameters which are Amount, days and InstPercentage. The problem is that when i add computed column in installment table

Cannot find definition though intellisense lists it?

守給你的承諾、 提交于 2020-03-01 03:10:11
问题 I'm getting a strange error with Visual Studio 10 (and now 11 as well). I have an extension method public static S Foo<S, T>(this S s) where S : IEnumerable<T> { return s; } Now if I call "".Foo(); // => 'string' does not contain a definition for 'Foo' and no extension method 'Foo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?) I'm not at all understanding what's happening under hood. The annoying part is that the

AppDomain Assembly not found when loaded from byte array

对着背影说爱祢 提交于 2020-02-27 06:42:28
问题 Please bear with me, I spent 30+ hours trying to get this work - but without success. At the start of my program I load an Assembly (dll) in bytearray and delete it afterwards. _myBytes = File.ReadAllBytes(@"D:\Projects\AppDomainTest\plugin.dll"); Later on in the program I create a new Appdomain, load the byte array and enumerate the types. var domain = AppDomain.CreateDomain("plugintest", null, null, null, false); domain.Load(_myBytes); foreach (var ass in domain.GetAssemblies()) { Console

AppDomain Assembly not found when loaded from byte array

旧街凉风 提交于 2020-02-27 06:41:45
问题 Please bear with me, I spent 30+ hours trying to get this work - but without success. At the start of my program I load an Assembly (dll) in bytearray and delete it afterwards. _myBytes = File.ReadAllBytes(@"D:\Projects\AppDomainTest\plugin.dll"); Later on in the program I create a new Appdomain, load the byte array and enumerate the types. var domain = AppDomain.CreateDomain("plugintest", null, null, null, false); domain.Load(_myBytes); foreach (var ass in domain.GetAssemblies()) { Console

How to use System.Lazy with Setter to Lazy Initialization of List in POCO Entities?

冷暖自知 提交于 2020-02-26 11:31:15
问题 I want to use System.Lazy to Lazy Initialization of my List in my Entites: public class Questionary { private Lazy<List<Question>> _questions = new Lazy<List<Question>>(() => new List<Question>()); public IList<Question> Questions { get { return _questions.Value; } set { _questions.Value = value; } } } The problem is on my SETTER, get this error: The property ' System.Lazy<T>.Value ' has no setter If i want to do MyInstance.Questions = new List<Question> { ... } ? How do I proceed? Update: I

Decompression error : The magic number in GZip header is not correct

不羁的心 提交于 2020-02-24 10:39:32
问题 I am new to System.IO.Compression I am trying to compress and decompress some information. For compression I used code project and it seems to work. I am compressing string at the moment. For decompressing I would like to docompress a Stream This is what I have at the moment var zipString = _compressor.Compress(request); using (var sw = new StreamWriter(req.GetRequestStream())) { sw.Write(zipString); sw.Close(); } WebResponse respStream = req.GetResponse(); Stream resp = respStream

How to highlight portion of a Rich TextBox WPF control if there are more than 2 spaces?

跟風遠走 提交于 2020-02-23 04:15:30
问题 I have a richtextbox control in my WPF 4.0 application. Now suppose I have a text like "hello how [space][space] r u? [space][space] I am fine" As can be noticed that there are two gaps between how and r as well as between ? and I . When this will happen then the portion will be highlighted with green e.g. how ..r and from ? to I will be highlighted with green color . i.e. if the space between two words are more than 2 then that will be highlighted with green. Is it possible to do in WPF