Code Monkey home page Code Monkey logo

Comments (6)

rhubarb-geek-nz avatar rhubarb-geek-nz commented on June 13, 2024 1

I tried to replicate using a minimal script

$workbooks = @{}

foreach ($workbookfile in 'foo', 'bar')
{
        $workbooks.Add($workbookfile,($workbookfile+' value'))
}

$workbooks

When run as a script it gives

Name                           Value
----                           -----
bar                            bar value
foo                            foo value

So that looks right.

Whn you say "it is not a hashtable" what does

$workbooks.GetType().Name

Also try using

$workbooks | Format-Table

to isolate the just the workbooks. Your output may include other objects

from powershell.

rhubarb-geek-nz avatar rhubarb-geek-nz commented on June 13, 2024 1

It looks like something is affecting the presentation of the output of the script, not the behaviour of the objects within the script.

from powershell.

rhubarb-geek-nz avatar rhubarb-geek-nz commented on June 13, 2024 1

I think there is something in your code that you are not showing

$workbooks['foo']

gave me

foo value

I suggest write an absolute minimal script like mine which shows the behaviour of the hashtable as expected, and add line by line until you get your script and see when the behaviour changes

It may simply be a typo somewhere.

from powershell.

mcgiany avatar mcgiany commented on June 13, 2024

When i run $workbooks.GetType() i get this:

IsCollectible              : False
DeclaringMethod            :
FullName                   : System.Collections.Hashtable
AssemblyQualifiedName      : System.Collections.Hashtable, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
Namespace                  : System.Collections
GUID                       : 68000a59-efdd-3d2a-a34a-7996b712988b
IsEnum                     : False
GenericParameterAttributes :
IsSZArray                  : False
GenericParameterPosition   :
ContainsGenericParameters  : False
StructLayoutAttribute      : System.Runtime.InteropServices.StructLayoutAttribute
Name                       : Hashtable
DeclaringType              :
Assembly                   : System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
BaseType                   : System.Object
IsByRefLike                : False
IsConstructedGenericType   : False
IsGenericType              : False
IsGenericTypeDefinition    : False
IsGenericParameter         : False
IsTypeDefinition           : True
IsSecurityCritical         : True
IsSecuritySafeCritical     : False
IsSecurityTransparent      : False
MemberType                 : TypeInfo
MetadataToken              : 33556676
Module                     : System.Private.CoreLib.dll
ReflectedType              :
TypeHandle                 : System.RuntimeTypeHandle
UnderlyingSystemType       : System.Collections.Hashtable
GenericTypeParameters      : {}
DeclaredConstructors       : {Void .ctor(Boolean), Void .ctor(), Void .ctor(Int32), Void .ctor(Int32, Single)…}
DeclaredEvents             : {}
DeclaredFields             : {_buckets, _count, _occupancy, _loadsize…}
DeclaredMembers            : {System.Collections.IHashCodeProvider get_hcp(), Void set_hcp(System.Collections.IHashCodeProvider), System.Collections.ICo
                             mparer get_comparer(), Void set_comparer(System.Collections.IComparer)…}
DeclaredMethods            : {System.Collections.IHashCodeProvider get_hcp(), Void set_hcp(System.Collections.IHashCodeProvider), System.Collections.ICo
                             mparer get_comparer(), Void set_comparer(System.Collections.IComparer)…}
DeclaredNestedTypes        : {System.Collections.Hashtable+Bucket, System.Collections.Hashtable+KeyCollection, System.Collections.Hashtable+ValueCollect
                             ion, System.Collections.Hashtable+SyncHashtable…}
DeclaredProperties         : {System.Collections.IHashCodeProvider hcp, System.Collections.IComparer comparer, System.Collections.IEqualityComparer Equa
                             lityComparer, System.Object Item [System.Object]…}
ImplementedInterfaces      : {System.Collections.IDictionary, System.Collections.ICollection, System.Collections.IEnumerable, System.Runtime.Serializati
                             on.ISerializable…}
IsInterface                : False
IsNested                   : False
IsArray                    : False
IsByRef                    : False
IsPointer                  : False
IsGenericTypeParameter     : False
IsGenericMethodParameter   : False
IsVariableBoundArray       : False
HasElementType             : False
GenericTypeArguments       : {}
Attributes                 : AutoLayout, AnsiClass, Class, Public, Serializable, BeforeFieldInit
IsAbstract                 : False
IsImport                   : False
IsSealed                   : False
IsSpecialName              : False
IsClass                    : True
IsNestedAssembly           : False
IsNestedFamANDAssem        : False
IsNestedFamily             : False
IsNestedFamORAssem         : False
IsNestedPrivate            : False
IsNestedPublic             : False
IsNotPublic                : False
IsPublic                   : True
IsAutoLayout               : True
IsExplicitLayout           : False
IsLayoutSequential         : False
IsAnsiClass                : True
IsAutoClass                : False
IsUnicodeClass             : False
IsCOMObject                : False
IsContextful               : False
IsMarshalByRef             : False
IsPrimitive                : False
IsValueType                : False
IsSignatureType            : False
TypeInitializer            :
IsSerializable             : True
IsVisible                  : True
CustomAttributes           : {[System.SerializableAttribute()], [System.Runtime.CompilerServices.NullableContextAttribute((Byte)1)], [System.Runtime.Com
                             pilerServices.NullableAttribute((Byte)0)], [System.Reflection.DefaultMemberAttribute("Item")]…}

But when i run GetType on normal hashtable i get this:

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Hashtable                                System.Object

The problem is also i cant do $workbooks["workbookName1"] because i get error that the index not exists.

from powershell.

mcgiany avatar mcgiany commented on June 13, 2024

Then why i cant access data via index?

from powershell.

microsoft-github-policy-service avatar microsoft-github-policy-service commented on June 13, 2024

📣 Hey @mcgiany, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

from powershell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.