473,799 Members | 3,866 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pass empty string

Hello,

I have a method:
Roles(CultureIn fo culture, RoleType? type, bool? open, bool?
beginWithEmpty, string[] userRoles)

How can I pass an empty string as userRoles? I tried:
Roles(Thread.Cu rrentThread.Cur rentCulture, RoleType.Admini strator,
false, true, new string[])

and

Roles(Thread.Cu rrentThread.Cur rentCulture, RoleType.Admini strator,
false, true, new string[0])

and

Roles(Thread.Cu rrentThread.Cur rentCulture, RoleType.Admini strator,
false, true, null)

But nothing works.

Thanks,
Miguel
Oct 22 '08 #1
6 2934
It depends on how you are checking parameters in Roles, but how about:

Roles(Thread.Cu rrentThread.Cur rentCulture, RoleType.Admini strator,
false, true, new string[] {string.Empty})
"shapper" <md*****@gmail. comwrote in message
news:86******** *************** ***********@o4g 2000pra.googleg roups.com...
Hello,

I have a method:
Roles(CultureIn fo culture, RoleType? type, bool? open, bool?
beginWithEmpty, string[] userRoles)

How can I pass an empty string as userRoles? I tried:
Roles(Thread.Cu rrentThread.Cur rentCulture, RoleType.Admini strator,
false, true, new string[])

and

Roles(Thread.Cu rrentThread.Cur rentCulture, RoleType.Admini strator,
false, true, new string[0])

and

Roles(Thread.Cu rrentThread.Cur rentCulture, RoleType.Admini strator,
false, true, null)

But nothing works.

Thanks,
Miguel
Oct 22 '08 #2
On Oct 22, 2:09*am, "Family Tree Mike"
<FamilyTreeM... @ThisOldHouse.c omwrote:
It depends on how you are checking parameters in Roles, but how about:

Roles(Thread.Cu rrentThread.Cur rentCulture, RoleType.Admini strator,
* false, true, new string[] {string.Empty})

"shapper" <mdmo...@gmail. comwrote in message

news:86******** *************** ***********@o4g 2000pra.googleg roups.com...
Hello,
I have a method:
Roles(CultureIn fo culture, RoleType? type, bool? open, bool?
beginWithEmpty, string[] userRoles)
How can I pass an empty string as userRoles? I tried:
Roles(Thread.Cu rrentThread.Cur rentCulture, RoleType.Admini strator,
false, true, new string[])
and
Roles(Thread.Cu rrentThread.Cur rentCulture, RoleType.Admini strator,
false, true, new string[0])
and
Roles(Thread.Cu rrentThread.Cur rentCulture, RoleType.Admini strator,
false, true, null)
But nothing works.
Thanks,
Miguel
In roles I am creating a list of Role, RoleList, and using this array
of string as follows:
RoleList.Where( r =(userRoles == null ||
userRoles.Conta ins(r.Type.ToSt ring()))

So if userRoles is empty, nothing was passed, all records are used.
If not then from RoleList get only the items which r.Type is contained
in RoleList.

But now I am not sure if I can use:
userRoles == null

Because I think I can't pass the string array as null.
Oct 22 '08 #3
On Tue, 21 Oct 2008 19:00:26 -0700, shapper <md*****@gmail. comwrote:
In roles I am creating a list of Role, RoleList, and using this array
of string as follows:
RoleList.Where( r =(userRoles == null ||
userRoles.Conta ins(r.Type.ToSt ring()))

So if userRoles is empty, nothing was passed, all records are used.
If not then from RoleList get only the items which r.Type is contained
in RoleList.

But now I am not sure if I can use:
userRoles == null

Because I think I can't pass the string array as null.
A concise-but-complete code sample would be helpful. Passing "null" or
"new string[0]" should work fine, I think, at least given what you've
showed us so far. So if it doesn't work, there's probably something else
going on.

But you need to show everything for us to figure out what that "something
else" is.

Pete
Oct 22 '08 #4
On Oct 22, 3:48*am, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Tue, 21 Oct 2008 19:00:26 -0700, shapper <mdmo...@gmail. comwrote:
In roles I am creating a list of Role, RoleList, and using this array
of string as follows:
RoleList.Where( r =(userRoles == null ||
userRoles.Conta ins(r.Type.ToSt ring()))
So if userRoles is empty, nothing was passed, all records are used.
If not then from RoleList get only the items which r.Type is contained
in RoleList.
But now I am not sure if I can use:
userRoles == null
Because I think I can't pass the string array as null.

A concise-but-complete code sample would be helpful. *Passing "null" or*
"new string[0]" should work fine, I think, at least given what you've *
showed us so far. *So if it doesn't work, there's probably something else *
going on.

But you need to show everything for us to figure out what that "something*
else" is.

Pete

Sorry, for the delay.
Basically, I have a class Role with Type, Description, Open, ...
properties that holds information on each of my application role.

Inside this class I have a method named List that returns the list of
roles to populate and input, checkboxes, etc ... So the format might
differ.
And sometimes I might need to filter the list ...

On my MVC view I want to call the method list but not directly ... I
prefer to call the a method on the View's ViewData object. So I have:

public static IList<RoleRoles (CultureInfo culture, RoleType?
type, bool? open, bool? beginWithEmpty, string[] userRoles) {
return Role.List(cultu re, type, open, beginWithEmpty,
userRoles);
}

public static IList<RoleList( CultureInfo culture, RoleType?
type, bool? open, bool? beginWithEmpty, string[] userRoles) {
IList<Roleroles = new List<Role>();
if (beginWithEmpty ?? false) roles.Add(new Role { Type = null,
Description = "---", Open = true });
switch (culture.TwoLet terISOLanguageN ame.ToLower()) {
case "pt":
roles.Add(new Role { Type = RoleType.Admini strator,
Description = "Administrador" , Open = false });
roles.Add(new Role { Type = RoleType.Collab orator,
Description = "Colaborado r", Open = false });
// ...
break;
}
return roles.Where(r =(userRoles == null ||
userRoles.Conta ins(r.Type.ToSt ring())) && (open == null || r.Open ==
open) && (type == null || r.Type == type)).OrderBy( r =>
r.Description). ToList();
} // List

And in my view I have:
<%foreach (Role role in
ViewData.Get<Ac countBook>("Acc ount").Roles(Th read.CurrentThr ead.CurrentCult ure,
RoleType.Admini strator, false, true, null)) {%>

And I am getting the error:
Member
'MyApp.Models.A ccountBook.Role s(System.Global ization.Culture Info,
MyApp.Security. Membership.Role Type?, bool?, bool?, string[])' cannot
be accessed with an instance reference; qualify it with a type name
instead

What am I doing wrong?

Thank You,
Miguel
Oct 22 '08 #5
On Wed, 22 Oct 2008 06:48:28 -0700, shapper <md*****@gmail. comwrote:
[...]
And I am getting the error:
Member
'MyApp.Models.A ccountBook.Role s(System.Global ization.Culture Info,
MyApp.Security. Membership.Role Type?, bool?, bool?, string[])' cannot
be accessed with an instance reference; qualify it with a type name
instead

What am I doing wrong?
Well, the first mistake was to post a question that has nothing to do with
your problem. :p

The second mistake was to not post the error message you're getting.
Especially since that error message clearly describes the problem: the
Roles() method is a static method, but you are calling it as if it were an
instance method.

The loop in which you call the Roles() method seems pointless to me, since
you never use the "role" loop variable. You just call the method in an
identical way for each "role" instance you get. But if you really
intended to implement things that way, you need to just do what the error
message says: use a type name instead of an instance reference for calling
the Roles() method.

Pete
Oct 22 '08 #6
On Oct 22, 7:49*pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Wed, 22 Oct 2008 06:48:28 -0700, shapper <mdmo...@gmail. comwrote:
[...]
And I am getting the error:
Member
'MyApp.Models.A ccountBook.Role s(System.Global ization.Culture Info,
MyApp.Security. Membership.Role Type?, bool?, bool?, string[])' cannot
be accessed with an instance reference; qualify it with a type name
instead
What am I doing wrong?

Well, the first mistake was to post a question that has nothing to do with *
your problem. *:p

The second mistake was to not post the error message you're getting. *
Especially since that error message clearly describes the problem: the *
Roles() method is a static method, but you are calling it as if it were an *
instance method.

The loop in which you call the Roles() method seems pointless to me, since *
you never use the "role" loop variable. *You just call the method in an*
identical way for each "role" instance you get. *But if you really *
intended to implement things that way, you need to just do what the error*
message says: use a type name instead of an instance reference for calling *
the Roles() method.

Pete
Thanks! I copied pasted my method I forgot to remove the static ...
then I was completely convinced that the problem was in the string
part because I had problems in it before ...

I didn't post the code inside the loop because I knew that wasn't the
problem ... about this one I was sure :-P ... lol

Thanks,
Miguel
Oct 23 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3571
by: DFS | last post by:
Architecture: Access 2003 client, Oracle 9i repository, no Access security in place, ODBC linked tables. 100 or so users, in 3 or 4 groups (Oracle roles actually): Admins, Updaters and ReadOnly. Each group sees a different set of menu options when they open the client and login to Oracle. For the sake of speed I use pass-through queries here and there for updates and deletes. I update their SQL property in code and execute them.
5
3751
by: Fresh Air Rider | last post by:
Hello Could anyone please explain how I can pass more than one arguement/parameter value to a function using <asp:linkbutton> or is this a major shortfall of the language ? Consider the following code fragments in which I want to list through all files on a directory with a link to download each file by passing a filename and whether or not to force the download dialog box to appear.
5
22087
by: Tee | last post by:
Hi, When I have a function like: private string xyz(string Text) I can call it without passing in a string with xyz("") or xyz(string.Empty) but if the paramater needed is an array like: private string xyz(string ArrayName)
9
1969
by: Paul | last post by:
What I am trying to do is as follows. I have a page with 3 links,that direct the user to 3 different pages when selected after login. So all link selections will first direct the user to a login page. Once the user logs in then they are directed to the appropriate link. So for all 3 links they all go to a login page, but each link must pass information to the login in page, specifically the page to go to after login takes place. -- Paul G...
4
5295
by: CsharpGuy | last post by:
I took over an web app (C#) were the developer put everything in a has table then called a method to execute a stored procedure, now I'm running into some issues were if I do an update and a NULL is passed that the field in the db is left empty and NULL is not entered in. So how can I pass a NULL value in a hashtable, execute the stored procedure and have NULL entered in the table instead of a blank field? here is an example of the code:...
2
1952
by: glenn | last post by:
Hi folks, I guess this question has to do with formatting dates. Seems like it should be a no brainer but have spent too much time hunting so I am posting the forum. I have a function that needs to pass a Date data-type that is empty much like a string would be empty if we were to place double quotes as in "". The reason it needs to be empty is because I am passing parameters to a
5
3685
by: wolf_y | last post by:
My question is simply: under what conditions will empty tags of the form <MOM></MOM> pass schema validation? Of course, the mirror question is: under what conditions will empty tags fail validation? The former seems to be an easier question to answer. XML files will arrive from around the world and must be schema validated before further processing and loading into a database, so I'm trying to foresee the various layouts that might be...
26
2800
by: anonieko | last post by:
In the past I always used "" everywhere for empty string in my code without a problem. Now, do you think I should use String.Empty instead of "" (at all times) ? Let me know your thoughts.
24
55243
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new EventHandler(Onbutton_click); I want to pass more information related that event. & want to use that
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.