how to define a static texture2D?

i want to assign a picture from a folder in my computer to a texture2d, but not in the inspector! i want to do it in script. but it gives me an error like this:

"NullReferenceException: Object reference not set to an instance of an object"

You can use Resources.Load or asset bundles to load textures on the fly without referencing them first. Just make sure to read the docs for its' limitations, especially if you're developing a streamed web player.

The Resources folder isn't exposed to the end user. It's used by you, and you alone when you develop your application. If you want your end user to add/change assets, you'll need to use other tools, such as the WWW class with the file:// syntax or the System.IO namespace of Mono (like this, for example). There are plenty of examples for it in the forum, and maybe even in the WIKI. Try searching for System.IO for example.