implicit-typing Questions

9

Solved

I have the following code: Func<string, bool> comparer = delegate(string value) { return value != "0"; }; However, the following does not compile: var comparer = delegate(string value) {...
Bathurst asked 11/2, 2011 at 4:17

18

Solved

I've been chatting with my colleagues the other day and heard that their coding standard explicitly forbids them to use the var keyword in C#. They had no idea why it was so and I've always found i...
Snatch asked 13/2, 2009 at 11:26

1

Solved

Say I have a simple class like this abstract class Foo { implicit val impInt: Int = 42 def f[A]()(implicit a: A): A val f2: Int = f() } When declaring val f2, compiler is able to infer that t...
Christy asked 3/4, 2016 at 17:51

1

I'm admittedly a Haskell newbie. To explore laziness, I created a function in ghci that returns its second argument: Prelude> let latter x y = y latter :: t -> t1 -> t1 I am able to cal...
Araroba asked 1/2, 2015 at 0:56

0

In the C# Coding Conventions, why does Microsoft suggest using implicit typing when the type of the variable is obvious from the right side of the assignment? I understand it's not necessary...
Whistle asked 24/9, 2014 at 19:50

7

Solved

In the simplified code below, if(city == "New York City") { var MyObject = from x in MyEFTable where x.CostOfLiving == "VERY HIGH" select x.*; } else { var MyObject = from x in MyEFTable wh...
Appetizer asked 5/1, 2012 at 23:37

8

Solved

The only advantage I can see to do: var s = new ClassA(); over ClassA s = new ClassA(); Is that later if you decide you want ClassB, you only have to change the RHS of the declaration. I gue...
Superintendent asked 27/7, 2009 at 23:9

3

Solved

I like using implicit typing for almost everything because it's clean and simple. However, when I need to wrap a try...catch block around a single statement, I have to break the implicit typing in ...
Wafer asked 28/12, 2012 at 17:13

4

Solved

foreach (var row in table.Rows) { DoSomethingWith(row); } Assuming that I'm working with a standard System.Data.DataTable (which has a collection of System.Data.DataRow objects), the variable 'r...
Emylee asked 27/9, 2012 at 13:17

5

Solved

Possible Duplicate: Advantage of var keyword in C# 3.0 yesterday I stumbled upon a recomendation from MS, that I should use var, when ever possible: http://msdn.microsoft.com/en-us/l...
Emalia asked 25/9, 2012 at 6:59

3

Solved

Why can't I use the array initializer with an implicitly typed variable? string[] words = { "apple", "strawberry", "grape" }; // legal string[] words = new string[]{ "apple", "strawberry", "grape"...
Itemized asked 8/9, 2011 at 16:32

3

Solved

Possible Duplicate: Resharper: vars Is there a reason that resharper suggests var thing1 = 5 as opposed to int thing1 = 5? It just seems that they mean the exact same thing except tha...
Hagans asked 5/6, 2011 at 20:56

5

Solved

Given the following: // not a problem int i = 2, j = 3; so it surprises me that this: // compiler error: Implicitly-typed local variables cannot have multiple declarators var i = 2, j = 3; do...
Dalmatic asked 9/2, 2011 at 20:30

13

In a book I'm reading it states the implicit typing makes the following code clearer than if you didn't use the var keyword: var words = new[] { "a", "b", null, "d" }; foreach (var item in words)...
Aswan asked 6/8, 2010 at 10:0

6

Solved

Does anyone know or care to speculate why implicit typing is limited to local variables? var thingy = new Foo(); But why not... var getFoo() { return new Foo(); }
Peafowl asked 5/5, 2009 at 12:59

1

Solved

Why is it not possible to have implicitly-typed variables at a class level within C# for when these variables are immediately assigned? ie: public class TheClass { private var aList = new...
Ortega asked 5/5, 2010 at 8:8

1

Solved

I've been developing .NET applications for 4 years. So far, I did not need to create any implicit conversions for the classes I authored. Could you provide real-life situations when you could not d...
Vorfeld asked 6/4, 2010 at 6:29

2

Solved

var x = new { a = "foobar", b = 42 }; List<x.GetType()> y; Is there a different way to do what I want to do here? If there's not, I don't really see all that much point in implicit types....
Kirkwood asked 15/10, 2009 at 6:8

5

Solved

I just installed a trial version of ReSharper and one of the first things I noticed is that it always suggests to replace explicitly typed local variables with implicitly typed ones, e.g: pu...
Permissive asked 16/3, 2009 at 15:32
1

© 2022 - 2024 — McMap. All rights reserved.