Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Iverron
May 13, 2012

Boz0r posted:

Is there somewhere I can find a tutorial for making a generic shop website in C# .NET MVC with a database?

Pro MVC series by Apress goes through a generic shop in it's first half. Cut my teeth on the MVC 3 version I think.

Adbot
ADBOT LOVES YOU

RICHUNCLEPENNYBAGS
Dec 21, 2010
Is there a good quick-start thing I can read about WPF apps? I'm making a very simple utility for my own use but I kinda find WinForms obnoxious and think I might like WPF better if I understood how to use it.

Mr Shiny Pants
Nov 12, 2012

RICHUNCLEPENNYBAGS posted:

Is there a good quick-start thing I can read about WPF apps? I'm making a very simple utility for my own use but I kinda find WinForms obnoxious and think I might like WPF better if I understood how to use it.

There is good video where someone goes trough building a stock ticker using winforms -> wrong WPF -> good WPF.

It is really good, has been posted here already and I can't for the life of me find it anymore. :(

Here it is: http://www.lab49.com/wp-content/uploads/2011/12/Jason_Dolinger_MVVM.wmv

Since I went trough this not long ago:

Use datatemplates in your XAML.
Don't name controls, bind them to your datacontext so they update and bind themselves automagically from your model/viewmodel.
Don't use events in your codebehind, bind commands to your controls. ( try keeping code in the code behind to a minimum )
Use ObservableCollections.
Things I ran into pretty fast: DataTemplateSelectors, Data Triggers, IValueConverters and some other stuff.

Find a good implementation of NotifyPropertyChanged and RelayCommand.

Wonder why you have CanExecute on your commands, figure out that you can use CanExecute to disable buttons based on the value of a property in your model. This whole concept of commands took me awhile to figure out. As with anything that MS does, stuff is complicated and things you would need in almost any project you need to build yourself. RelayCommand, BaseNotifyPropertyChanged etc etc.

Or use something like the MVVM Light Toolkit.

Mr Shiny Pants fucked around with this message at 09:17 on Mar 29, 2015

Boz0r
Sep 7, 2006
The Rocketship in action.
I can't find the ASP.NET Web Application template in Visual Studio 2013 Premium Update 4, like here:



I can only find MVC 4 Web Forms. What's the deal?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Boz0r posted:

I can't find the ASP.NET Web Application template in Visual Studio 2013 Premium Update 4, like here:



I can only find MVC 4 Web Forms. What's the deal?

There's no such thing as "MVC Web forms" -- MVC and web forms are two different platforms. When you choose that template, it pops up a second screen that lets you configure your project as MVC, web forms, or web API.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Ithaqua posted:

There's no such thing as "MVC Web forms" -- MVC and web forms are two different platforms. When you choose that template, it pops up a second screen that lets you configure your project as MVC, web forms, or web API.

Here's my question about this: why go to the trouble of a whole separate namespace with a ton of duplication for WebAPI, then have the WebAPI template include MVC?

Mr Shiny Pants posted:

There is good video where someone goes trough building a stock ticker using winforms -> wrong WPF -> good WPF.

It is really good, has been posted here already and I can't for the life of me find it anymore. :(

Here it is: http://www.lab49.com/wp-content/uploads/2011/12/Jason_Dolinger_MVVM.wmv

Since I went trough this not long ago:

Use datatemplates in your XAML.
Don't name controls, bind them to your datacontext so they update and bind themselves automagically from your model/viewmodel.
Don't use events in your codebehind, bind commands to your controls. ( try keeping code in the code behind to a minimum )
Use ObservableCollections.
Things I ran into pretty fast: DataTemplateSelectors, Data Triggers, IValueConverters and some other stuff.

Find a good implementation of NotifyPropertyChanged and RelayCommand.

Wonder why you have CanExecute on your commands, figure out that you can use CanExecute to disable buttons based on the value of a property in your model. This whole concept of commands took me awhile to figure out. As with anything that MS does, stuff is complicated and things you would need in almost any project you need to build yourself. RelayCommand, BaseNotifyPropertyChanged etc etc.

Or use something like the MVVM Light Toolkit.

That sounds fine, thanks. I mostly write MVC and WebAPI stuff so I don't think this should be a huge conceptual leap.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

RICHUNCLEPENNYBAGS posted:

Here's my question about this: why go to the trouble of a whole separate namespace with a ton of duplication for WebAPI, then have the WebAPI template include MVC?


:shrug:

ASP .NET vNext is changing this, I believe.

Iverron
May 13, 2012

Ithaqua posted:

:shrug:

ASP .NET vNext is changing this, I believe.

Aye. There's a single template for both in vNext. Both share the same Controller base, etc. now as well.

There's a lot of good stuff like this in vNext, including a built in Basic DI mechanism so that the default Internet template doesn't break every DI framework out there :shepspends:

Captain Capacitor
Jan 21, 2008

The code you say?
On Thursday I got a chance to sit in on a walkthrough of M-Brace with Don Syme. In terms of a simple "just give me some clusters and let me do poo poo with it" it's pretty impressive.

Farm out some URLs to download:
code:
let urls = [| ("bing", "http://bing.com"); ("yahoo", "http://yahoo.com"); 
              ("google", "http://google.com"); ("msn", "http://msn.com") |]

let write (text: string) (stream: Stream) = async { 
    use writer = new StreamWriter(stream)
    writer.Write(text)
    return () 
}


/// Cloud workflow to download a file and wave it into cloud storage
let download (name: string, uri: string) = cloud {
    let webClient = new WebClient()
    let! text = Cloud.OfAsync (webClient.AsyncDownloadString(Uri(uri)))
    do! CloudFile.Delete(sprintf "pages/%s.html" name)
    let! file = CloudFile.WriteAllText(text,path=sprintf "pages/%s.html" name)
    return file
}
It's pretty smart. Smart enough to know what libraries you're referencing and automatically bundle those up to run in the clusters. There's no support for native DLLs yet, but there's a workaround until it's fixed in the next release of M-Brace.

Mr Shiny Pants
Nov 12, 2012

Captain Capacitor posted:

On Thursday I got a chance to sit in on a walkthrough of M-Brace with Don Syme. In terms of a simple "just give me some clusters and let me do poo poo with it" it's pretty impressive.

Farm out some URLs to download:
code:
let urls = [| ("bing", "http://bing.com"); ("yahoo", "http://yahoo.com"); 
              ("google", "http://google.com"); ("msn", "http://msn.com") |]

let write (text: string) (stream: Stream) = async { 
    use writer = new StreamWriter(stream)
    writer.Write(text)
    return () 
}


/// Cloud workflow to download a file and wave it into cloud storage
let download (name: string, uri: string) = cloud {
    let webClient = new WebClient()
    let! text = Cloud.OfAsync (webClient.AsyncDownloadString(Uri(uri)))
    do! CloudFile.Delete(sprintf "pages/%s.html" name)
    let! file = CloudFile.WriteAllText(text,path=sprintf "pages/%s.html" name)
    return file
}
It's pretty smart. Smart enough to know what libraries you're referencing and automatically bundle those up to run in the clusters. There's no support for native DLLs yet, but there's a workaround until it's fixed in the next release of M-Brace.

Looks cool, does it need azure? Or will it work on regular Windows servers?

wwb
Aug 17, 2004

RICHUNCLEPENNYBAGS posted:

Here's my question about this: why go to the trouble of a whole separate namespace with a ton of duplication for WebAPI, then have the WebAPI template include MVC?

In a nutshell, history and politics and requirements to maintain backwards compatibility. The MVC stack was mature when the guys doing the web API dove in so they wanted to do some things different even though the semantics were largely similar. The MVC group didn't want to break stuff so they ended up creating 2 parallel stacks with lots of similar terminology that is getting fixed in ASP.NET v5.

bobua
Mar 23, 2003
I'd trade it all for just a little more.

I'm messing with my first azure site(first site too) and publishing it is a mess. When I publish a change, it randomly doesn't happen. I'm not talking about CSS or page changes that could be getting cached on my end, I mean new controller files\functions aren't there. When I terminal in, the new files are there\updated but the live site pretends like they aren't. I've tried restarting and manually stopping\starting the site. I'm not using deploy slots and I haven't specifically set up any sort of caching. Any ideas?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

bobua posted:

I'm messing with my first azure site(first site too) and publishing it is a mess. When I publish a change, it randomly doesn't happen. I'm not talking about CSS or page changes that could be getting cached on my end, I mean new controller files\functions aren't there. When I terminal in, the new files are there\updated but the live site pretends like they aren't. I've tried restarting and manually stopping\starting the site. I'm not using deploy slots and I haven't specifically set up any sort of caching. Any ideas?

Your browser's cache.

Mr Shiny Pants
Nov 12, 2012

bobua posted:

I'm messing with my first azure site(first site too) and publishing it is a mess. When I publish a change, it randomly doesn't happen. I'm not talking about CSS or page changes that could be getting cached on my end, I mean new controller files\functions aren't there. When I terminal in, the new files are there\updated but the live site pretends like they aren't. I've tried restarting and manually stopping\starting the site. I'm not using deploy slots and I haven't specifically set up any sort of caching. Any ideas?

Chrome developer tab "disable cache" on the network tab.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Also, use MVC bundling for scripts and styles which will automatically add its own timestamp to the URL so you don't have to worry about caching.

bobua
Mar 23, 2003
I'd trade it all for just a little more.

I may be confused here...

How can my browser cache that a new function does not exist in a controller? Like I said, this isn't a static page or even razor.

I can create a brand new controller\views, publish them, login to the azure portal - terminal and see them there, reset the app, and it still won't let me use them for 20-60 minutes.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Hm, that's interesting. I've yet to run into something like that. What are you using to publish? Are you publishing to an Azure Website or some other setup? The changes don't show up immediately, but do they eventually show up without you having re-deploy? I'd almost assume some issue with the build process on your end (which you could try fixing by cleaning the solution before publishing, or deleting your bin/obj folders).

epswing
Nov 4, 2003

Soiled Meat

bobua posted:

I may be confused here...

How can my browser cache that a new function does not exist in a controller? Like I said, this isn't a static page or even razor.

I can create a brand new controller\views, publish them, login to the azure portal - terminal and see them there, reset the app, and it still won't let me use them for 20-60 minutes.

Just to assure you that you're not crazy, I've witnessed this before. Published from VS 2013, loaded a page up in the browser, and it was as if I was looking at an older version of the code. I restarted the site, and a couple F5s later the new code seemed to "kick in". Happened once, hasn't occurred since :iiam:

RangerAce
Feb 25, 2014

bobua posted:

I may be confused here...

How can my browser cache that a new function does not exist in a controller? Like I said, this isn't a static page or even razor.

I can create a brand new controller\views, publish them, login to the azure portal - terminal and see them there, reset the app, and it still won't let me use them for 20-60 minutes.

I last time I had this happen, I had to go manually delete some bin and obj folders (Clean Solution wasn't doing the trick). After that, things were working as intended.

bobua
Mar 23, 2003
I'd trade it all for just a little more.

RangerAce posted:

I last time I had this happen, I had to go manually delete some bin and obj folders (Clean Solution wasn't doing the trick). After that, things were working as intended.

This is the next thing I'll try, since I've had some issues like this before.

Thanks guys, just wanted to make sure I wasn't missing something silly.

RICHUNCLEPENNYBAGS
Dec 21, 2010

bobua posted:

This is the next thing I'll try, since I've had some issues like this before.

Thanks guys, just wanted to make sure I wasn't missing something silly.

Oh, yeah. I remember one time I moved a view into shared, but the old, non-shared view wasn't deleted when I re-deployed, which caused something similar for me.

ljw1004
Jan 18, 2005

rum

RICHUNCLEPENNYBAGS posted:

Here's my question about this: why go to the trouble of a whole separate namespace with a ton of duplication for WebAPI, then have the WebAPI template include MVC?

File > New > VB > Web > ASP.NET > Empty, and then check the checkbox marked "WebAPI".

This gets you a nice clean blank template that has no MVC stuff, only WebAPI.

Inverness
Feb 4, 2009

Fully configurable personal assistant.
Visual Studio 2015 product line announced.

I see they're adding CodeLens to 2015 Professional. That's one of those neat features that I ended up not giving two shits about because it was hidden behind the Ultimate paywall.

edmund745
Jun 5, 2010
I have tried looking for this answer online and can't find anything useful, since I suppose the question contains too many keywords.

Using vb.net (VS Express 2012)
1. I have a class/an object.
2. that class/object has a list in it. One of these ---> https://msdn.microsoft.com/en-us/library/6sh2ey19%28v=vs.110%29.aspx
3. how do I use the list methods without declaring the list public in the class?

I cannot recall how to do this.... Declaring the list as public works, but it seems odd to do that when you declare all the other properties private.... Seems like there would be a way.

I can find pages that talk about using lists from within the object that contains them,
and pages that talk about objects/properties/methods,
and pages that talk about lists of objects,
and pages that talk about lists of lists,
but I can't find any pages that talk about using a list inside an object, from outside that object.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

edmund745 posted:

I have tried looking for this answer online and can't find anything useful, since I suppose the question contains too many keywords.

Using vb.net (VS Express 2012)
1. I have a class/an object.
2. that class/object has a list in it. One of these ---> https://msdn.microsoft.com/en-us/library/6sh2ey19%28v=vs.110%29.aspx
3. how do I use the list methods without declaring the list public in the class?

I cannot recall how to do this.... Declaring the list as public works, but it seems odd to do that when you declare all the other properties private.... Seems like there would be a way.

I can find pages that talk about using lists from within the object that contains them,
and pages that talk about objects/properties/methods,
and pages that talk about lists of objects,
and pages that talk about lists of lists,
but I can't find any pages that talk about using a list inside an object, from outside that object.

This is basic access modifiers.

  • Public is accessible anywhere
  • Private is accessible only within the class it's defined in
  • Protected is accessible from the class it's defined in and any subclasses
  • Internal is equivalent to public, but only within the assembly it's defined in

There's also protected internal, which is a fairly uncommon one. You can safely pretend it doesn't exist for now.

If you want to use a property of an object from outside that object, it has to be public. If this sounds really simple, it's because it is. If you're having trouble with something relating to this, it's almost certainly a design issue we can help you with. More specificity is always better; paste us some code.

[edit]
Also, stop using VS2012 express. It's crippled compared to the VS2013 Community edition. And VS2015 Community will be out fairly soon and definitely warrants an upgrade.

New Yorp New Yorp fucked around with this message at 02:03 on Apr 1, 2015

crashdome
Jun 28, 2011

edmund745 posted:

but I can't find any pages that talk about using a list inside an object, from outside that object.

To add to Ithaqua's post:

You can also specify protection to your get/set accessors. For example, lets say you have a list or collection in a class that you want to allow the ability to Add/Remove items but, you don't want anyone to replace the collection. You want to specify a private set accessor or no set accessor at all and initialize the collection in your constructor. A reason for this might be that you subscribe to events internally within your class or generally want the collection container itself to never change:

code:
public class Foo
{
     public Foo 
     {
           Mylist = new List<Bars>();
     }

     private List<Bars> _myList;
     public List<Bars> BarList
     {
          get { return _mylist; }
          private set 
          { 
               _myList = value;
               //Hook up events or other things here 
          }
     }
}
That way you will never have anyone do this:
code:
Foo myFoo = new Foo();
myFoo.BarList = new List<Bars>();
...and royally screw up things.

You can run into other issues though. Optionally you could use a Readonly collection if you don't want anyone to modify the contents from outside your class.

epswing
Nov 4, 2003

Soiled Meat
Is this really not possible?

How can I stop IISExpress from dumping every detail of every request into the Visual Studio 2012 Output window?

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug
I found this http://forums.iis.net/post/1992357.aspx which sounds like what you wanted

Rooster Brooster
Mar 30, 2001

Maybe it doesn't really matter anymore.
For a good laugh, Tomas Petricek posted about an "unusual" way to get F#-style pattern matching into C# 6 using Throw-Driven-Development. It's clever, hilarious, and also sad because pattern matching is so useful I momentarily considered trying this out in a real project.

Space Whale
Nov 6, 2014
Managed to give myself a bit of a LINQ puzzle today.

I want to remove objects from list A based on on a property shared with another type of object in another list. That is, I want to trim a list of foo based on foo.A not matching bar.A, where both are just integers.

I'm not quite sure how to tell LINQ to do this. Basically I want to do listofA.RemoveAll(x => x.propIcareAbout == listB.SomehowReferenceEAchElementOfB.propIcareAbout );

Rooster Brooster
Mar 30, 2001

Maybe it doesn't really matter anymore.
So you basically want listOfA.RemoveAll((x) => listOfB.Any((b) => b.prop == x.prop))? https://msdn.microsoft.com/en-us/library/bb534972.aspx

Space Whale
Nov 6, 2014

Rooster Brooster posted:

So you basically want listOfA.RemoveAll((x) => listOfB.Any((b) => b.prop == x.prop))? https://msdn.microsoft.com/en-us/library/bb534972.aspx

That's exactly what I wanted, I just suck at LINQ. Thanks!

epswing
Nov 4, 2003

Soiled Meat

gariig posted:

I found this http://forums.iis.net/post/1992357.aspx which sounds like what you wanted

Is that supposed to go in applicationhost.config? If so, where in applicationhost.config is this supposed to go? I tried a couple locations, with no change in behavior. (Yes, I restarted IISExpress!)

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Ithaqua posted:

This is basic access modifiers.

  • Public is accessible anywhere
  • Private is accessible only within the class it's defined in
  • Protected is accessible from the class it's defined in and any subclasses
  • Internal is equivalent to public, but only within the assembly it's defined in

Nitpick: Internal in VB.Net is called Friend :glomp:

edmund745 posted:

I have tried looking for this answer online and can't find anything useful, since I suppose the question contains too many keywords.

Using vb.net (VS Express 2012)
1. I have a class/an object.
2. that class/object has a list in it. One of these ---> https://msdn.microsoft.com/en-us/library/6sh2ey19%28v=vs.110%29.aspx
3. how do I use the list methods without declaring the list public in the class?

I cannot recall how to do this.... Declaring the list as public works, but it seems odd to do that when you declare all the other properties private.... Seems like there would be a way.

I can find pages that talk about using lists from within the object that contains them,
and pages that talk about objects/properties/methods,
and pages that talk about lists of objects,
and pages that talk about lists of lists,
but I can't find any pages that talk about using a list inside an object, from outside that object.

What, exactly, are the "list methods" you want to access from outside the object?

Reading you literally, if you want to access, say, myObject.myList.Add(item) or myObject.myList.Clear(), then yeah, making the list public is what you want to do. (crashdome is correct that you can use a readonly property to let people use the List methods, without being able to outright replace the List with a new one. But in the particular case of a List, this wouldn't do much since people could just call .Clear() to empty the list and .AddRange() to replace it with anything they want. All a "readonly" modifier really does in this case is prevent people from setting the list to Nothing and causing trouble.)

If you want to let people use only some methods of the list - a common case would be the ability to add stuff but not remove it - then you set up a few public methods or properties that expose only the stuff you want from the private list.

If you want to access the individual objects inside the list, but not the list itself, same thing - add properties that fetch the items, without revealing anything about the list (or even that there is a list).

Example:

code:
public class myClass

private myList as list(of item) = new list(of item)

'this method will let outsiders add stuff to the list, but they won't be able to do anything else
public sub AddItem(newItem as item)
if mylist is nothing then mylist = new list(of item)
mylist.add(newItem)
end sub

'this will return a single item from the list if available, and is also a pretty stupidly written property
public readonly property GetItem(index as integer) as item
get
if mylist is nothing orelse mylist.count <= index then return nothing else return mylist(index)
end get
end property

'better version: this will return an "IEnumerable", the tl;dr version of which is that it is a collection that you can filter, search, iterate ("for each"), etc. through, but not actually modify (add/remove stuff)
'if you just returned a List the "readonly" wouldn't really protect you - it would prevent people from replacing the list outright but they could still e.g. call .Clear() and .Remove() on it
public readonly property myItems() as ienumerable(of item)
get
return mylist  'since a list is a kind of IEnumerable you can just return it - external objects accessing the property will not know that it could do more, as the List-specific stuff like Add() or Clear() will remain unavailable
end get
end property

end class

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Question about file locking. I'm doing this:
code:
        Dim files
        files = Directory.EnumerateFiles("d:\somewhere\", "*.csv")
        For Each filename As String In files
            Dim afile As FileIO.TextFieldParser = New FileIO.TextFieldParser(filename)
            Dim csv As String()
            afile.TextFieldType = FileIO.FieldType.Delimited
            afile.Delimiters = New String() {","}
            afile.HasFieldsEnclosedInQuotes = False
            Do While Not afile.EndOfData
                csv = afile.ReadFields
                'buncha csv parsing stuff
            Loop
            afile = Nothing
            File.Move(filename, "d:\somewhere\Processed\" & Path.GetFileName(filename).ToString)
        Next
However, on the File.Move at the end, I'm getting a file access error. I had thought destroying the afile object would remove the lock, is there something else? I obviously can't desttory the files object populated by Enumerate Files because I'm still looping through it.

Rooster Brooster
Mar 30, 2001

Maybe it doesn't really matter anymore.
Having never used that class before, do you need to call Close()? https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.textfieldparser.close%28v=vs.110%29.aspx

Mr Shiny Pants
Nov 12, 2012

Scaramouche posted:

Question about file locking. I'm doing this:
code:
        Dim files
        files = Directory.EnumerateFiles("d:\somewhere\", "*.csv")
        For Each filename As String In files
            Dim afile As FileIO.TextFieldParser = New FileIO.TextFieldParser(filename)
            Dim csv As String()
            afile.TextFieldType = FileIO.FieldType.Delimited
            afile.Delimiters = New String() {","}
            afile.HasFieldsEnclosedInQuotes = False
            Do While Not afile.EndOfData
                csv = afile.ReadFields
                'buncha csv parsing stuff
            Loop
            afile = Nothing
            File.Move(filename, "d:\somewhere\Processed\" & Path.GetFileName(filename).ToString)
        Next
However, on the File.Move at the end, I'm getting a file access error. I had thought destroying the afile object would remove the lock, is there something else? I obviously can't desttory the files object populated by Enumerate Files because I'm still looping through it.

I think you need to dispose the stream before moving it.

Can you use "using" around the TextReader or something? Don't know if VB has it. Otherwise dispose of the textreader.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt


Either that or use a Using afile As New FileIO.TextFieldParser(filename) block.

Setting objects to Nothing is not actually disposing of them. :iiaca: You're not demolishing your car, you're just throwing away your car keys and hope somebody notices the abandoned car and gets around to demolishing it. In this particular case, you're throwing away the keys of a running car.

NihilCredo fucked around with this message at 22:17 on Apr 1, 2015

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Mr Shiny Pants posted:

I think you need to dispose the stream before moving it.

Can you use "using" around the TextReader or something? Don't know if VB has it. Otherwise dispose of the textreader.

You sure are correct. Dispose() fixed it, though I didn't try .Close() Rooster Brooster.

Bad habit from the VB 6 days I guess. Actually a trenchant question, is there any point in setting an object to Nothing any more?

Adbot
ADBOT LOVES YOU

crashdome
Jun 28, 2011

NihilCredo posted:

. (crashdome is correct that you can use a readonly property to let people use the List methods, without being able to outright replace the List with a new one. But in the particular case of a List, this wouldn't do much since people could just call .Clear() to empty the list and .AddRange() to replace it with anything they want. All a "readonly" modifier really does in this case is prevent people from setting the list to Nothing and causing trouble.)

Hmm.. I actually meant using something like ReadOnlyCollection or ReadOnlyObservableCollection. I had completely forgotten about the readonly keyword as I never use it.


NihilCredo posted:

In this particular case, you're throwing away the keys of a running car.

Yes but, can a car run without keys? :viggo:

Edit:

Scaramouche posted:

Actually a trenchant question, is there any point in setting an object to Nothing any more?

I depends on if your class implements IDisposable or not. If you have a class that doesn't and you want to clear out a container class and remove the reference as soon as possible, it sure helps. Example would be if you had a service class that uses Foo through a private field or something and when the service is idle or dormant you want to release it without going through the trouble of implementing IDisposable on Foo.

In fact, you should probably just avoid IDisposable unless you absolutely have unmanaged resources inside your class.

crashdome fucked around with this message at 23:45 on Apr 1, 2015

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply