The Artima Developer Community
Sponsored Link

C# Answers Forum
String array declaration

2 replies on 1 page. Most recent reply: Oct 28, 2004 3:16 PM by Victor Huynh

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Supriya

Posts: 3
Nickname: sup
Registered: Jun, 2003

String array declaration Posted: Jun 12, 2003 1:01 PM
Reply to this message Reply
Advertisement
Hi,

I am new to C# programming language. I am developing small
project that is viewing digital photos as Slideshow.

I am getting syntax error that is "Syntax
error, ']'expected" while compiling the following code
snippet,

string[] path = new string[3];
path[0] = "c:\\digitalphotos\\Image1.jpg";
path[1] = "c:\\digitalphotos\\Image2.jpg";
path[2] = "c:\\digitalphotos\\Image3.jpg";

Can anyone tell me why i am getting such error?

Thanks inadvance.


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: String array declaration Posted: Jun 14, 2003 4:58 PM
Reply to this message Reply
You didn't give the line number for the compiler error and the code you have posted here seems to be okay, so the error maybe coming from some other part of your code.

FYI, here are some tricks that might help you with your app: You can use the DirectoryInfo object (you need to import System.IO, or fully reference it as System.IO.DirectoryInfo) to get all the files of a certain type in a folder (or simply all the files, if you want). You can also get the "My Pictures" folder from the Environment object. Here's an example of how you would use these if your object wanted to get thumbnails for all the jpg files in the "My Pictures" folder (assuming your object implements the "AddThumbnail()" method):

import System;     // Has Environment object.
import System.IO;  // Has of DirectoryInfo and FileInfo.
 
// ...
 
string myPix = Environment.GetFolderPath( Environment.SpecialFolder.MyPictures );
DirectoryInfo myPixInfo = new DirectoryInfo( myPix );
foreach( FileInfo pic in myPixInfo.GetFiles( "*.jpg" ) )
   AddThumbnail( pic.FullName );

Victor Huynh

Posts: 1
Nickname: vichuynh
Registered: Oct, 2004

Re: String array declaration Posted: Oct 28, 2004 3:16 PM
Reply to this message Reply
It's ok for you to declare it and even initialize it, but in order to go further, you have to put it in a function.

public string[] TestString = new string[3];

// This is wrong:
// TestString[0] = "Something";

public void SomeFunction() {
TestString[0] = "Something";
}

Good luck.

Flat View: This topic has 2 replies on 1 page
Topic: Get www site ( Screen Scrapes ) faster??? -= .NET C# / VB.NET =- Previous Topic   Next Topic Topic: assign socket permission to ntd winform

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use