Search Results

Search found 8301 results on 333 pages for 'types'.

Page 2/333 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Concrete Types or Interfaces for return types?

    - by SDReyes
    Today I came to a fundamental paradox of the object programming style, concrete types or interfaces. Whats the better election for a method's return type: a concrete type or an interface? In most cases, I tend to use concrete types as the return type for methods. because I believe that an concrete type is more flexible for further use and exposes more functionality. The dark side of this: Coupling. The angelic one: A concrete type contains per-se the interface you would going to return initially, and extra functionality. What's your thumb's rule? Is there any programming principle for this? BONUS: This is an example of what I mean http://stackoverflow.com/questions/491375/readonlycollection-or-ienumerable-for-exposing-member-collections

    Read the article

  • Java vs c++ types

    - by folone
    I've recently had a question about coledatetime java implementation, and Chris said, that the problem might lay in type conversions: cpp-float vs java-float (Or maybe cpp-date vs java-date. Not types, but..). Now I have several questions on this: Is there a table of comparison for java vs c++ types? If type conversions is the problem, in my situation (I have a db with OLEDate records, already created with some c++ program. I need to read and write to that db, so that the OLEDate field compatibility remained: my java code reads proper dates, and c++ program is not affected with what the java program wrote to the db.), what would you do: Use COleDateTime to retrieve the date with JNI? Create your own implementation at all costs (using broader types, or anything else)? Is there anything, I'm missing here?

    Read the article

  • What C# data types can be nullable types?

    - by Randy Minder
    Can someone give me a list, or point me to where I can find a list of C# data types that can be a nullable type? For example: I know that Nullable<int> is ok I know that Nullable<byte[]> is not. I'd like to know which types are nullable and which are not. BTW, I know I can test for this at runtime. However, this is for a code generator we're writing, so I don't have an actual type. I just know that a column is "string" or "int32" etc. Thanks.

    Read the article

  • mapping list of different types implementing same function?

    - by sisif
    I want to apply a function to every element in a list (map) but the elements may have different types but all implement the same function (here "putOut") like an interface. However I cannot create a list of this "interface" type (here "Outputable"). How do I map a list of different types implementing the same function? main :: IO () main = do map putOut lst putStrLn "end" where lst :: [Outputable] -- ERROR: Class "Outputable" used as a type lst = [(Out1 1),(Out2 1 2)] class Outputable a where putOut :: a -> IO () -- user defined: data Out1 = Out1 Int deriving (Show) data Out2 = Out2 Int deriving (Show) instance Outputable Out1 where putOut out1 = putStrLn $ show out1 instance Outputable Out2 where putOut out2 = putStrLn $ show out2 I cannot define it this way: data Out = Out1 Int | Out2 Int Int putOut Out1 = ... putOut Out2 = ... because this is a library and users should be able to extend Out with their own types

    Read the article

  • .Net Round-trip Types

    - by Fujiy
    I making a method that generate a unique string key for some parameters. But the same key if call with same values. I just accept primitive types, string, DateTime, Guid, and Nullable(since I append types together, I can distinguish who is int and who is int?), because I can convert all to string without lost values or precision.(for float and double a use ToString("R"), to DateTime ToString("O")). Exists a easy way to know which types I can transform in strings without conflict? And how do this transform(how I said before, float, double and datetime have specific ways) Thanks

    Read the article

  • C++ : Swapping template class elements of different types?

    - by metamemetics
    template< class T1, class T2 > class Pair { T1 first; T2 second; }; I'm being asked to write a swap() method so that the first element becomes the second and the second the first. I have: Pair<T2,T1> swap() { return Pair<T2,T1>(second, first); } But this returns a new object rather than swapping, where I think it needs to be a void method that changes its own data members. Is this possible to do since T1 and T2 are potentially different class types? In other words I can't simply set temp=first, first=second, second=temp because it would try to convert them to different types. I'm not sure why you would potentially want to have a template object that changes order of its types as it seems that would cause confusion but that appears to be what I'm being asked to do.

    Read the article

  • Why are enums considered compound types?

    - by FredOverflow
    Arrays, functions, pointers, references, classes, unions, enumerations and pointers to members are compound types. My understanding of a compound type is that is based on other type(s). For example, T[n], T* and T& are all based on T. Then what other type(s) is an enumeration based on? Or if my understanding of compound types is incorrect, what exactly is it about a type that makes it a compound type? Is compound simply a synonym for user-defined?

    Read the article

  • Higher-kinded Types with C++

    - by Venkat Shiva
    This question is for the people who know both Haskell (or any other functional language that supports Higher-kinded Types) and C++... Is it possible to model higher kinded types using C++ templates? If yes, then how?

    Read the article

  • Is there any functional difference between immutable value types and immutable reference types?

    - by Kendall Frey
    Value types are types which do not have an identity. When one variable is modified, other instances are not. Using Javascript syntax as an example, here is how a value type works. var foo = { a: 42 }; var bar = foo; bar.a = 0; // foo.a is still 42 Reference types are types which do have an identity. When one variable is modified, other instances are as well. Here is how a reference type works. var foo = { a: 42 }; var bar = foo; bar.a = 0; // foo.a is now 0 Note how the example uses mutatable objects to show the difference. If the objects were immutable, you couldn't do that, so that kind of testing for value/reference types doesn't work. Is there any functional difference between immutable value types and immutable reference types? Is there any algorithm that can tell the difference between a reference type and a value type if they are immutable? Reflection is cheating. I'm wondering this mostly out of curiosity.

    Read the article

  • Nullable types and ?? operator C# [en-US]

    - by ruimachado
    Nullable types vs Non-nullable types   While developing our C# projects its frequent the null comparison operation to avoid null exceptions. This simple operation is mainly coded using the "var x = null" code example inside an if clause. However not all types of variables are nullable, which means that setting a variable to null is not allowed in every cases, it depends on what kind of type are you defining. But what if there was an extension to your non-nullable type that would convert your variable types to nullable? This extension really exists. As I said before in C# you have nullable types which represent all the values of an underlying type, and an additional null value and can be declared easily using "T?", where T is the type of the variable and for example the normal int type cannot be null, so its a non-nullable type, however if you define a "int?" your variable can be null, what you do is convert a non-nullable type to a nullable type. Example: int x=null;     Not allowed     int? x=null;   Allowed     While using nullable types you can check if a variable is null the same way you do it with nullable types:     But what about setting a default value when a certain variable is null?   In this cases the c# .net framework let you set a default value when you try to assign a nullable type to a non-nullable type, using the ?? operator. If you don't use this operator you can still catch the InvalidOperationException which is throw in this cases. For example  without the ?? operator :     Using the ?? operator your code becomes cleaner and more easy to read and you get a bonus, you can set a default value for multiple variables using the ?? in a chain set.     That’s it,   Thanks, Rui Machado rpmachado.wordpress.com

    Read the article

  • Cannot iterate of a collection of Anonymous Types created from a LINQ Query in VB.NET

    - by Atari2600
    Ok everyone, I must be missing something here. Every LINQ example I have seen for VB.NET anonymous types claims I can do something like this: Dim Info As EnumerableRowCollection = pDataSet.Tables(0).AsEnumerable Dim Infos = From a In Info _ Select New With {.Prop1 = a("Prop1"), .Prop2 = a("Prop2"), .Prop3 = a("Prop3") } Now when I go to iterate through the collection(see example below), I get an error that says "Name "x" is not declared. For Each x in Infos ... Next It's like VB.NET doesn't understand that Infos is a collection of anonymous types created by LINQ and wants me to declare "x" as some type. (Wouldn't this defeat the purpose of an anonymous type?) I have added the references to System.Data.Linq and System.Data.DataSetExtensions to my project. Here is what I am importing with the class: Imports System.Linq Imports System.Linq.Enumerable Imports System.Linq.Queryable Imports System.Data.Linq Any ideas?

    Read the article

  • C++ Types Impossible to Name

    - by Kirakun
    While reading Wikipedia's page on decltype, I was curious about the statement, Its [decltype's] primary intended use is in generic programming, where it is often difficult, or even impossible, to name types that depend on template parameters. While I can understand the difficulty part of that statement, what is an example where there is a need to name a type that cannot be named under C++03? EDIT: My point is that since everything in C++ has a declaration of types. Why would there ever be a case where it is impossible to name a type? Furthermore, aren't trait classes designed to yield type informations? Could trait classes be an alternative to decltype?

    Read the article

  • C#: Get key and value types of non-generic IDictionary at runtime

    - by Yang Zou
    there. I am wondering how I can get the key and value types of a non-generic IDictionary at runtime. For generic IDictionary, we can use reflection to get the generic arguments, which has been answered here. But for non-generic IDictionary, for instance, HybridDictionary, how can I get the key and value types? Thanks. Edit: I may not describe my problem properly. For non-generic IDictionary, if I have HyBridDictionary, which is declared as HyBridDictionary dict = new HyBridDictionary(); dict.Add("foo" , 1); dict.Add("bar", 2); How can I find out the type of the key is string and type of the value is int? Did I make the question clear? Thanks.

    Read the article

  • assembly.GetTypes() does not return all types

    - by meta
    I try to lead the types from an .dll (which is also referenced in the executing project). I call: public static void LoadPlugin(string pluginFile) { Assembly assembly = Assembly.LoadFrom(pluginFile); foreach (Type type in assembly.GetTypes()) { // play with it } } It loads just a few of them: public partial class Mathematics : UserControl, IMathematics, IPortable and public partial class Welcome : UserControl but the next one, and some others, are ignored: public partial class Test : UserControl, ITest, IPortable They all stand in the same assembly, under the same namespace. The public static void LoadPlugin(string pluginFile) method is located in other assembly that is also referenced in the executing project. No exceptions are thrown. What could be the issues for not loading all the types? Any ideas?

    Read the article

  • f# types' properties in inconsistent order and of slightly differing types

    - by philbrowndotcom
    I'm trying to iterate through an array of objects and recursively print out each objects properties. Here is my object model: type firmIdentifier = { firmId: int ; firmName: string ; } type authorIdentifier = { authorId: int ; authorName: string ; firm: firmIdentifier ; } type denormalizedSuggestedTradeRecommendations = { id: int ; ticker: string ; direction: string ; author: authorIdentifier ; } Here is how I am instantiating my objects: let getMyIdeasIdeas = [| {id=1; ticker="msfqt"; direction="buy"; author={authorId=0; authorName="john Smith"; firm={firmId=12; firmName="Firm1"}};}; {id=2; ticker="goog"; direction="sell"; author={authorId=1; authorName="Bill Jones"; firm={firmId=13; firmName="ABC Financial"}};}; {id=3; ticker="DFHF"; direction="buy"; author={authorId=2; authorName="Ron James"; firm={firmId=2; firmName="DEFFirm"}};}|] And here is my algorithm to iterate, recurse and print: let rec recurseObj (sb : StringBuilder) o= let props : PropertyInfo [] = o.GetType().GetProperties() sb.Append( o.GetType().ToString()) |> ignore for x in props do let getMethod = x.GetGetMethod() let value = getMethod.Invoke(o, Array.empty) ignore <| match value with | :? float | :? int | :? string | :? bool as f -> sb.Append(x.Name + ": " + f.ToString() + "," ) |> ignore | _ -> recurseObj sb value for x in getMyIdeas do recurseObj sb x sb.Append("\r\n") |> ignore If you couldnt tell, I'm trying to create a csv file and am printing out the types for debugging purposes. The problem is, the first element comes through in the order you'd expect, but all subsequent elements come through with a slightly different (and confusing) ordering of the "child" properties like so: RpcMethods+denormalizedSuggestedTradeRecommendationsid: 1,ticker: msfqt,direction: buy,RpcMethods+authorIdentifierauthorId: 0,authorName: john Smith,RpcMethods+firmIdentifierfirmId: 12,firmName: Firm1, RpcMethods+denormalizedSuggestedTradeRecommendationsid: 2,ticker: goog,direction: sell,RpcMethods+authorIdentifierauthorName: Bill Jones,RpcMethods+firmIdentifierfirmName: ABC Financial,firmId: 13,authorId: 1, RpcMethods+denormalizedSuggestedTradeRecommendationsid: 3,ticker: DFHF,direction: buy,RpcMethods+authorIdentifierauthorName: Ron James,RpcMethods+firmIdentifierfirmName: DEFFirm,firmId: 2,authorId: 2, Any idea what is going on here?

    Read the article

  • Instantiating a list of parameterized types, making beter use of Generics and Linq

    - by DanO
    I'm hashing a file with one or more hash algorithms. When I tried to parametrize which hash types I want, it got a lot messier than I was hoping. I think I'm missing a chance to make better use of generics or LINQ. I also don't like that I have to use a Type[] as the parameter instead of limiting it to a more specific set of type (HashAlgorithm descendants), I'd like to specify types as the parameter and let this method do the constructing, but maybe this would look better if I had the caller new-up instances of HashAlgorithm to pass in? public List<string> ComputeMultipleHashesOnFile(string filename, Type[] hashClassTypes) { var hashClassInstances = new List<HashAlgorithm>(); var cryptoStreams = new List<CryptoStream>(); FileStream fs = File.OpenRead(filename); Stream cryptoStream = fs; foreach (var hashClassType in hashClassTypes) { object obj = Activator.CreateInstance(hashClassType); var cs = new CryptoStream(cryptoStream, (HashAlgorithm)obj, CryptoStreamMode.Read); hashClassInstances.Add((HashAlgorithm)obj); cryptoStreams.Add(cs); cryptoStream = cs; } CryptoStream cs1 = cryptoStreams.Last(); byte[] scratch = new byte[1 << 16]; int bytesRead; do { bytesRead = cs1.Read(scratch, 0, scratch.Length); } while (bytesRead > 0); foreach (var stream in cryptoStreams) { stream.Close(); } foreach (var hashClassInstance in hashClassInstances) { Console.WriteLine("{0} hash = {1}", hashClassInstance.ToString(), HexStr(hashClassInstance.Hash).ToLower()); } }

    Read the article

  • C# 4: Real-World Example of Dynamic Types

    - by routeNpingme
    I think I have my brain halfway wrapped around the Dynamic Types concept in C# 4, but can't for the life of me figure out a scenario where I'd actually want to use it. I'm sure there are many, but I'm just having trouble making the connection as to how I could engineer a solution that is better solved with dynamics as opposed to interfaces, dependency injection, etc. So, what's a real-world application scenario where dynamic type usage is appropriate?

    Read the article

  • Silverlight 4 Data Binding with anonymous types.

    - by Anthony
    Does anyone know if you can use data binding with anonymous types in Silverlight 4? I know you can't in previous versions of silverlight, you can only databind to public class properties and anonymous type properties are internal. Just wondering if anyone has tried it in silverlight 4? Thanks in advanced

    Read the article

  • Unpacking tuple types in Scala

    - by jpalecek
    I was just wondering, can I decompose a tuple type into its components' types in Scala? I mean, something like this trait Container { type Element } trait AssociativeContainer extends Container { type Element <: (Unit, Unit) def get(x : Element#First) : Element#Second }

    Read the article

  • Design Patterns : Question about "Types"

    - by contactmatt
    Would someone please explain to me what the below paragraph means? This is a snippet from "Design Patterns: Elements of Reusable OO software" Part of an object's interface may be characterized by one type, and other parts by other types. Two objects of the same type need only share parts of their interfaces. Interfaces can contain other interfaces as subsets. - Design Patterns - Elements of Reusable OO software, pg 13

    Read the article

  • Determining if types alias to the same underlying type in C++

    - by emchristiansen
    I'd like to write a templated function which changes its behavior depending on template class types passed in. To do this, I'd like to determine the type passed in. For example, something like this: template <class T> void foo() { if (T == int) { // Sadly, this sort of comparison doesn't work printf("Template parameter was int\n"); } else if (T == char) { printf("Template parameter was char\n"); } } Is this possible?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >